Jump to content

Php Sessions Help.....


googlit

Recommended Posts

Hi

 

i have searched the forum for half an hour but kind find the answers i am looking for,

 

I have created a site which is restricted and users are required to log in prior to anything else, i have a session that carries there logged in status but i also want to carry the full details of the user to the checkout page so it will auto complete fields for the customers. do i need to create a session that carries the Mysql data or can i use the original session? also i am unsure how to code the session as i have just moved over to PHP from ASP (i saw the light so to speak)

 

my db fields are as follows:

 

User_ID

Username

Password

First_Name

Last_Name

Phone_primary

Phone_Alt

Email

Address1

Address2

Address3

Town

County

Postcode

 

any help would be appreciated guys....

 

Thanks

 

Link to comment
https://forums.phpfreaks.com/topic/203238-php-sessions-help/
Share on other sites

You only need one session. As mentioned above, you could just store the user's ID when they log in and use that to query their details later. You can store any number of variables in the $_SESSION array once you call session_start(). Just storing the user ID is what I would personally do but if you want to reduce database load you can load some commonly used variables in there like the name and such. Sessions are fairly secure but session hijacking still exists so don't store sensitive information.

 

For example, in your login page after you have queried in all their information:

 

session_start();
$_SESSION['name'] = $databaseRow['firstname'] . ' ' . $databaseRow['lastname'];
$_SESSION['email'] = $databaseRow['email'];
// And so forth

 

Then later on if you want to auto fill in forms on another page you could do something like this:

session_start();
echo '<form method="post">';
echo '<b>User Name:</b> <input type="text" name="usersname" ';

if(isset($_SESSION['name'])
   echo "value=\"{$_SESSION['name']}\" ";

echo '/> </form>';

 

Link to comment
https://forums.phpfreaks.com/topic/203238-php-sessions-help/#findComment-1064906
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.