
<?
session_start();
header("Cache-control: private");
?>
The session_start() and the header has to be placed on the TOP (before any output) of every page you want these variables to follow along with the user. Once you have started the session, to add variables to the session, all you have to do is use the _Session varible. For example, if you want to have a username variable with a value of "Bobert", you write:
<? $_SESSION["username"] = "Bobert"; ?>Now, just think of $_SESSION["username"] as any other variable like $username. You can do anything you want with it, and it'll follow around your website from one page to another. A session is ended whenever the visitor leaves your site, if you ever want to destroy/kill a variable inside the session, just use this command:
<? unset($_SESSION["variable"]); ?>and replace variable, with the name of the variable you want to delete. If you want to end the session all together while still keeping the visitor on your site, use:
<? session_destroy(); ?>That logs off the user. I hope this tutorial helped you in realizing an alternative, safer way PHP has come up to deal with site global variables than cookies.
Copyright © 2000-2008 Spoono, LLC. All rights reserved.
Network: Reseller Web Hosting by Spoono Host | Spoonloads | Absolute Cross
Terms of Service | Privacy Policy.