googlit Posted May 28, 2010 Share Posted May 28, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/203238-php-sessions-help/ Share on other sites More sharing options...
The Eagle Posted May 28, 2010 Share Posted May 28, 2010 You'll need to carry the MySQL data, I don't recall sessions carrying all that information to be safe. Quote Link to comment https://forums.phpfreaks.com/topic/203238-php-sessions-help/#findComment-1064868 Share on other sites More sharing options...
Pikachu2000 Posted May 29, 2010 Share Posted May 29, 2010 You can simply store the User_ID field in a session var while logging the user in, then run another db query to retrieve the associated record while loading the checkout page script. Quote Link to comment https://forums.phpfreaks.com/topic/203238-php-sessions-help/#findComment-1064904 Share on other sites More sharing options...
DWilliams Posted May 29, 2010 Share Posted May 29, 2010 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>'; Quote Link to comment https://forums.phpfreaks.com/topic/203238-php-sessions-help/#findComment-1064906 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.