Jump to content

Does PHP allow you to put 2 variables in a session?


Drezard

Recommended Posts

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.
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 password

Is that what you want?

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.