Drezard Posted September 17, 2006 Share Posted September 17, 2006 Hello, I want to store 2 variables in one session at the same time.How would i do this (Code examples please)- Cheers, Daniel Quote Link to comment https://forums.phpfreaks.com/topic/21026-does-php-allow-you-to-put-2-variables-in-a-session/ Share on other sites More sharing options...
gterre Posted September 17, 2006 Share Posted September 17, 2006 this is what I would put<?phpsession_start();$firstname="Daniel";$lastname="Cheers";$_SESSION['username'] = $lastname.', '.$firstname;?> Quote Link to comment https://forums.phpfreaks.com/topic/21026-does-php-allow-you-to-put-2-variables-in-a-session/#findComment-93328 Share on other sites More sharing options...
Drezard Posted September 17, 2006 Author Share Posted September 17, 2006 then how do i get em out?- cheers, daniel Quote Link to comment https://forums.phpfreaks.com/topic/21026-does-php-allow-you-to-put-2-variables-in-a-session/#findComment-93329 Share on other sites More sharing options...
gterre Posted September 17, 2006 Share Posted September 17, 2006 <?phpecho $_SESSION['username'];?>the session must be started on the beginning of the page prior to using any session variables. Quote Link to comment https://forums.phpfreaks.com/topic/21026-does-php-allow-you-to-put-2-variables-in-a-session/#findComment-93330 Share on other sites More sharing options...
markbett Posted September 17, 2006 Share Posted September 17, 2006 echo $_SESSION['username']; Quote Link to comment https://forums.phpfreaks.com/topic/21026-does-php-allow-you-to-put-2-variables-in-a-session/#findComment-93332 Share on other sites More sharing options...
Drezard Posted September 17, 2006 Author Share Posted September 17, 2006 like what happens if i want to pass 2 variables from one page to another. So $_SESSION['user'] = $user. ',' .$pass;and then on the next page.$user = $_SESSION['userinfo']$pass = $_SESSION['userinfo']Thanks, Daniel Quote Link to comment https://forums.phpfreaks.com/topic/21026-does-php-allow-you-to-put-2-variables-in-a-session/#findComment-93340 Share on other sites More sharing options...
imartin Posted September 17, 2006 Share Posted September 17, 2006 first page would be [code]$_SESSION['user'] = $user;$_SESSION['password'] = $password;[/code]second page would be [code]$user = $_SESSION['user'];$password = $_SESSION['password'];[/code]$_SESSION is an array, whatever vars you wish to cary page to page in your program can be put in this array as elements, you refer to these elements by the index you give them. ie, "user" is an element in the $_SESSION array that we set above, when you wish to refer to it you will use $_SESSION["user"], "user" being the index. Quote Link to comment https://forums.phpfreaks.com/topic/21026-does-php-allow-you-to-put-2-variables-in-a-session/#findComment-93342 Share on other sites More sharing options...
wildteen88 Posted September 17, 2006 Share Posted September 17, 2006 Prehaps Drezard mean two values in one SESSION variable rather than having two session variables. So prehaps Drezard wants something like this:[code=php:0]session_start();$username = 'someuser';$password = 'somepass';// NOw we create 1 session var to store the username and password:$_SESSION['userinfo']['username'] = $username;$_SESSION['userinfo']['password'] = $password;[/code]The above code creates 1 session variable ($_SESSION['userinfo'] which is an array) and holds two values the username and password.To retieve the username and password use this:$_SESSION['userinfo']['username'] - to grab the username$_SESSION['userinfo']['password'] - to grab the passwordIs that what you want? Quote Link to comment https://forums.phpfreaks.com/topic/21026-does-php-allow-you-to-put-2-variables-in-a-session/#findComment-93470 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.