Jump to content

A better session data storage method??


AbydosGater

Recommended Posts

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.