Hi, first time poster, long time lurker.
I have a problem with session variables that i can't seem to solve. I have a login script that works absolutely perfectly, SQL statements with the session variables retreive and store data properly, the session variables are updated and modified properly and all comparisons are being performed correctly. The file is being require() in the first line of each page that the login is being required on. The only problem is, i can't get the $_SESSIOn variables to output to the browser.
I have tried using the classic echo $SESSION['foobar'] and printf('%s', $SESSION['foobar']) but they both output null. And when echoing data from the check_login file, it refuses to output anything for the $_SESSION variables, even when echoing the sprintf SQL query, it shows the query EXCEPT for the session variable it's seeking, but the query performs properly retreiving the correct data.
Can someone help me out with this problem?
Here's a snippet of my check_login.php code:
<?php
session_start();
if (!isset($_SESSION['username']) || !isset($_SESSION['password']))
{
$logged_in = 0;
return;
}
else
{
if(!get_magic_quotes_gpc())
{
$_SESSION['username'] = addslashes($_SESSION['username']);
}
$query = sprintf('SELECT username, password, rank FROM users WHERE username =\'%s\'', $_SESSION['username']);
$result = mysql_query($query);
if(!$result || mysql_num_rows($result) == 0)
{
$logged_in = 0;
unset($_SESSION['username']);
unset($_SESSION['password']);
}
$row = mysql_fetch_row($result);
$row[1] = stripslashes($row[1]);
$_SESSION['password'] = stripslashes($_SESSION['password']);
if($_SESSION['password'] == $row[1])
{
$logged_in = 1;
}
else
{
$logged_in = 0;
unset($_SESSION['username']);
unset($_SESSION['password']);
}
}
$_SESSION['username'] = stripslashes($_SESSION['username']);
echo $row[0];
unset($row[0]);
?>