Is it possible to set a session variable within a function?
Im having problems with a function of mine. what it does is selects from the sessions table the session ID (which is stored in the session variable upon login.) However I want it so that should a user not access a pafe via the login page it registers that a guest is viewing.
Should no session variable be set Id assume when i query the table it would return zero. therefore with an if function I add the user to the sessions table as a guest. and set guest session variables.
Heres the problem. It adds the gust no problem, but when i refresh or go to another page it increaeses the gust count by one each time. (i.e the query returned zero again).
Ill post some code, coz i dont think i was very clear.
<?php
//The session variables used is:
//$sessionID
session_start();
function CheckUser($sessionID) {
//See if this user has a session, if not we assign one
$query = "SELECT * FROM sessions WHERE sessionIP='$sessionID'";
$result = mysql_query($query);
CheckMySQL();
$returned = mysql_num_rows($result);
if ($returned == 0) {
//No rows were found
//This user's session has either expired or has not accessed this page via the login page. We add a session.
$ThisSessionID = rand(0, 100000000);
$MCuserID = "guest";
$ThisIP = $_SERVER['REMOTE_ADDR'];
$time = time();
$query = "INSERT INTO sessions (sessionID, MCsessionID, sessionIP, time) VALUES ('$ThisSessionID', '$MCuserID', '$ThisIP', '$time')";
$result = mysql_query($query);
CheckMySQL();
//register session variables
$sessionID = $ThisSessionID;
session_register("MCuserID");
session_register("sessionID");
}
}?>
any help?!