Need to know, or get a handle on SESSION variables in your dynamic sites for your PHP?

This is a refrence "cheat sheet," not a tutorial , so I provide tutorial links at the end.

SESSION variables, no matter what Server Model language you use, must first be declared (login) and destroyed at the end (logout). Assuming you have PHP 4.1 or higher. 

 

Initialize Session

This must be at the top of every page that will call/use a Session variable.

<?php session_start(); ?>

Register (declare) a Session variable

To add a Session variable that will be carried till the browser is closed or you kill it yourself.

<?php session_register("mySessionVariable"); ?>

Assigning value to a Session variable

Values added to a Session variable can be letters (ABCabc), numbers (1, 200, 999.99, etc.) making them good for usernames/userID's when logged into a site.

<?php $_SESSION["mySessionVariable"] = "MEMBER"; ?>

Unregister a Session variable

Logging out requires we unregister any and all Session variables used for our application and the users' account.

<?php session_unregister("mySessionVariable"); ?>

Destroy a Session

We should always destroy a Session to help complete a logout.

<?php session_destroy(); ?>


DMXzone Tutorials & Articles to learn more

PHP Documentation