I try to create a session and registering varibles. The varibles are vital to the function of user related areas. On two previous forums they never gave me a response to this problem. I hope you guys can provide a response :
function is_user() {
global $username;
session_start();
if (isset($_SESSION['username'])) {
$username = $_SESSION['username'];
$result = mysql_query ("SELECT * FROM session WHERE username='$username'");
IF(mysql_num_rows($result)==0) {
echo "You have failed to meet session standards please note cookies must be enabled!\n";
echo "<meta http-equiv=\"refresh\" content=\"3;URL=index.php?index=login\">\n";
}
//they have cleared authentication
} ELSE {
echo "session was never registered\n";
}
}
function login2($username, $passwd) {
global $username, $passwd; //Global varibles needed to complete logins through index linking.
$result = mysql_query ("SELECT * FROM user WHERE username='$username'")
or die ("Could Not retrieve files");
while ($user = mysql_fetch_array ($result)) {
if($user[2]==$passwd) {
srand((double)microtime()*1000000); //seed the generator
$session_id = md5(uniqid(rand())); //Build the session ID.
session_cache_limiter("private");
$_SESSION['username']==$username;
session_id($session_id);
session_register($username);
session_start();
$ipuser = getenv ("REMOTE_ADDR"); // get the ip number of the user
$ctime = time();
mysql_query("UPDATE session SET username='$username', time='$ctime', host_addr='$ipuser', guest='0', sid='$session_id' WHERE username='$ipuser'");
include("header.php");
tabletop();
echo "You are logging in please wait...\n";
echo "<meta http-equiv=\"refresh\" content=\"5;URL=index.php?index=act&action=usercp\">\n";
echo "If you havent logged in please <a href=\"index.php?index=act&action=usercp\">Click Here</a>\n";
} else {
include("header.php");
tabletop();
echo "<CENTER><b><font size=\"2\" class=\"title\">Wrong Password<br><Br><br>\n";
echo "<meta http-equiv=\"refresh\" content=\"2;URL=index.php?index=login\">\n";
}
}
tablebottom();
include("footer.php");
}
I call the is_user function in user related areas. When I access the area I get the message I put as 'Session was never registered (varible)' The error was defined when I used ISSET to find whether the session varible $_SESSION['username'] is empty or not and it returned False causing the error.
Could you help me? note: this contains where the session begins and the function used to check it