On my most recent script that I am debugging now I have about 7 sessions running
They arent totally independent I dont think
each one is defined with
session_register('variable');
then in each script that you want to have access to the variables defined (the variables are defined when you execute the "session_register" function, probably in the script that processes a user login or data from a database
you use session_start(); to call the session
Now, depending on if you have register globals enabled on your server, after using session_start(); the variables can be called one of two ways
if register globals is on:
$variable
if register globals is not on:
the session variables are stored in an associative array much like that of the post or get vars:
$_SESSION['variable']
that should be it, you can register as many sessions as you want, if you call session_register in more then one script that run in conjunction, just make sure to use a uniqe name for each one because as soon as you session_start it makes them all available and you dont want to cross reference them...
for example:
in my script, the user fills out the login form which posts to this script:
<?php
//Check user login script
//MySQL Connection Informaion
include 'db.php';
/*Convert to simple variables
$username = $_POST['username'];
$password = $_POST['password'];
*/
if((!$username) || (!$password)){
echo "Please enter ALL of the information! <br />";
include 'login_form.php';
exit();
}
//convert password to md5 encryption
$password = md5($password);
//Check user info in database
$sql = mysql_query("SELECT * FROM members WHERE username='$username' AND
password='$password' AND activated='1'");
$login_check = mysql_num_rows($sql);
if($login_check > 0){
while($row = mysql_fetch_array($sql)){
foreach($row AS $key=>$val){
$key = stripslashes($val);
}
//Register session variables
session_register('first_name');
$_SESSION['first_name'] = $row['first_name'];
session_register('last_name');
$_SESSION['last_name'] = $row['last_name'];
session_register('email_address');
$_SESSION['email_address'] = $row['email_address'];
session_register('special_user');
$_SESSION['user_level'] = $row['user_level'];
session_register('tag');
$_SESSION['tag'] = $row['tag'];
session_register('username');
$_SESSION['username'] = $row['username'];
session_register('info');
$_SESSION['info'] = $row['info'];
mysql_query("UPDATE members SET last_login=now() WHERE username='$username'");
header("Location: login_success.php");
}
} else {
echo "You could not be logged in! Either the username and password do not
match or you have not activated your membership!<br />
Please try again!<br />";
include 'login_form.php';
}
?>
Whenever I want access to these variables which are defined based on user data in the database (most imporatanly "user_level" which defines what pages they can and cant view) I simply call session_start() at the BEGINNING of the script I want to use them in, and thats that.
Hope this helps