rootKID Posted February 17, 2013 Share Posted February 17, 2013 (edited) Yo W3S again... i have this little project of my own.its a little hard to explain, but also only a theory, so feel free to ask in to it... i have been watching a project called TBdev (its a torrent project, yes, but hear me out first...). i have been trying to see how they have builded up their login system with cookies. and to be more specific, their functions inside the main-file called bittorrent.php. anyways, i am kinda building my own functions for this to work, but im trying to build in a little different way then them... i think... here is my functions: function login_session($db_output, $update_user_db = 0){set_my_session( "uid" );//name the sessionset_my_session( "pass" );//name the sessionset_my_session( "stylesheet" );//name the sessionif ($update_user_db == '1'){ @mysql_query("UPDATE users SET last_login = ".TIME_NOW." WHERE id = $id");}}function set_my_session( $name ){CODE HERE...}function unset_my_session( $session_name ){unset($_SESSION['{$session_name}']);}function logout_session() {unset_my_session('uid');unset_my_session('pass');} now, as you see. then the login_session is the main function here to login with..now, this is my login file: $res = mysql_query("SELECT id, passhash, username, secret FROM users WHERE username = " . sqlesc($username) . " AND status = 'confirmed'");$row = mysql_fetch_assoc($res);login_session($row); now, as you see. im taking ALL my DB info out into the function. now here comes the part from where im a little lost, because now i need to build up the function that builds it.that would be the (set_my_session)... my point is to take ALL rows/data out FROM where the username are...so i can see WHAT the kind of data the user has.... BUT. as you see on the login_session, im trying to give them different names for Each and one, so i can see the difference on them...that is the way the TBdev project did it, and that was the thing that was giving into me mostly... so here comes the question...if i am going to take ALL the data out from DB, and i need to know the different name on each and one.is it possible to take the row/col name... like if one of the rows were named 'user_id', is it possible to use THAT name to the session?, and as you can see here at my project right now, do you think i can get it to work?... -thanks for advice if possible!... EDIT: and ohh, as you see... im also needing to UNSET the sessions again, that is where the names for the different sessions come into the picture, but give me some advice, because im pretty surtent that this one will work, just needing a little advice to go on with... -thanks!... Edited February 17, 2013 by rootKID Link to comment Share on other sites More sharing options...
justsomeguy Posted February 18, 2013 Share Posted February 18, 2013 You can use a foreach loop to go through the array and get both the column names and values if that's what you're asking. You can pass those pairs to the function to set a value in the session, but it seems sort of useless to have a function that only does this: $_SESSION[$name] = $value; Why use a function when you can use that line? The same with unset, why use a function that just has a single line instead of just putting that line in your code? Link to comment Share on other sites More sharing options...
rootKID Posted March 2, 2013 Author Share Posted March 2, 2013 (edited) sorry for late reply, well. the answer is simple. i am trying to develop it so the user (before login to the website), can check/uncheck a box that will seperate sessions and cookies, so if box checked, it will use cookies, and if not, sessions. for fun ... Edited March 3, 2013 by rootKID Link to comment Share on other sites More sharing options...
justsomeguy Posted March 4, 2013 Share Posted March 4, 2013 It would probably make sense to use a class for that, where the class has various methods for the different situations and a property to tell it which set of methods to use. Either way though, sessions also use cookies. Link to comment Share on other sites More sharing options...
rootKID Posted March 16, 2013 Author Share Posted March 16, 2013 sorry for late reply, i have figured out myself. thanks for all answers! ... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now