Jump to content

Using sessions to pass variable from one page to another


dmccabe

Recommended Posts

Ok I am creating a form to be filled out online, but before filling in the form I want people to authenticate against my ldap server.

 

The authentication is fine, but I want it to then pass the username to the next page where they fill in an online form.

 

I believe the best way is to use a session, but I have looked at the sessions help on php.net and am not getting anywhere fast, so can someone give me a quick example and explanation of how this would work?

 

To recap, I am simply wanting to pass the username they enter in to a form to the next page and then use it later in that page.

On any page in which you want to access the SESSION (either writing the username or reading from it), you must first start the session:

session_start();

that line should be the very first line of the file (well, second line site <?php should be first)

 

Then, in the script, you can read/write to the variable $_SESSION (which is an array):

$_SESSION['username'] = 'foobar'; //Set username here

and read from it on other pages:

print $_SESSION['username'];

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.