Jump to content

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

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.