Originally posted by utahcon
do you know any good Tuts on Sessions... for some reason my head wont wrap around them...
Not really, but they are very simple!!!
I'll give you a quick explanation.
A session is basically the server just storing information about a user as variables. You choose which variables to set. Also EVERY page which will be using the sessions absoloutly MUST start with session_start(); no waya round it. Its a fact that must be obeyed.
To register a session we use this function: session_register();
eg:
<?php
//Tell PHP that this script will be using sessions
session_start();
//Now we have the variable that we want to set
//(this could be from a POST form if you wanted)
$VariableToSet = "green"
session_register($VariableToSet);
//Now we have registered the session variable.
//If we want we can echo the variable
echo "A $VariableToSet apple"; //A green apple
?>
GREAT! yopur thinking, why register a variable when it is the same as the variable name?! you crazy fool!
Yes maybe it is, but if that was a script called register.php and we come along and open another script called something.php, here is where the magic happens.....
<?php
//In this script we want to echo the variable set in the previous
//script. I.e the variable $VariableToSet.
//First we tell PHP that we want to use session variables
session_start();
//Now we can echo the variable
echo "A $VariableToSet apple";
?>
The second script echos exactly the same thing!
Sessions are sueful for example if you want to store say a username thorughout a person's visit to your site. Everytime a script wants to use $VariableToSet it can as long as session_start(); was used.
Sessions can do alot more but im still a noob(ish) so thats what i use them for. Mainly for searching through a MySQL database about a users info.
But have fun! HOPEFULLy, that made sense to you!!!!