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.
Link to comment
Share on other sites

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?
Link to comment
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.