AbydosGater Posted November 22, 2006 Share Posted November 22, 2006 Hi,...In my login script, if the user logs in correctly with the right information.. I set the session variables with the code below.. And send them to the members.php...[quote]<?php session_register("user"); $_SESSION['username'] = $username; $_SESSION['password'] = $password; //-- Rest Of Info On The User $_SESSION['member_id'] = $user['member_id']; $_SESSION['email'] = $user['email']; $_SESSION['CL'] = $user['CL']; $_SESSION['banned'] = $user['banned']; //-- Session Variables End echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"0; URL=members.php\">";//Leave out the opening and closing tags, i only put them in here so the code is in colour...?>[/quote]I think its silly that i have so many session vars...Is there any way to set it in an associtave array? so like the script has the $user.. I just have to $user['db_field_name']; for the info..How would i set it so the session saves an array so i would have to call say.. for example the username..$_SESSION['user']['username'];Is this possible?Thanks Abydos Quote Link to comment Share on other sites More sharing options...
CheesierAngel Posted November 22, 2006 Share Posted November 22, 2006 Why should you keep all this stuff in session variables ?If you storage the member_id in a session variable isn't it enough to requery the rest of the info from a database ? Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 22, 2006 Author Share Posted November 22, 2006 yeah it is, but it would be easier to just use an associtave array! Quote Link to comment Share on other sites More sharing options...
CheesierAngel Posted November 22, 2006 Share Posted November 22, 2006 Try it out! Make a test page and try if you can assign and get the variables...[code]<?phpsession_start();$_SESSION['user'] = array( 'name' => 'myName', 'email' => 'emailAddress')echo '<pre>';print_r($_SESSION['user']);echo '</pre>';?>[/code] Quote Link to comment Share on other sites More sharing options...
taith Posted November 22, 2006 Share Posted November 22, 2006 aah... the wonder of arrayed arrays...[code]$result = mysql_query("SELECT * FROM users WHERE `username`='$username' AND `password`='$password' limit 1");$_SESSION[user]= mysql_fetch_array($result);[/code]then you can access vars like $_SESSION[user][username]personally... i dont use anything but arrayed arrays for holding user info. Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 22, 2006 Author Share Posted November 22, 2006 YAY!! Thanks guys! brill, will add the code now! Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 22, 2006 Share Posted November 22, 2006 As cheesier said, you're better off just storing minimal information (username or user_id) in the session and querying for it on every page. If you don't do that, you have to remember to update variables in $_SESSION every time you allow the user to update their personal information which can become a PITA. Quote Link to comment Share on other sites More sharing options...
AbydosGater Posted November 22, 2006 Author Share Posted November 22, 2006 I was thinking about that.. And i decided i want it so that if the user changes any account information they will have to log out and in again, i know its annoying for them but tuff :P Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.