Working with sessions
Posted: Mon Jun 04, 2007 12:46 pm
We've just set up PHP on our new web server however I can't seem to get sessions working properly. The session ID gets created and carried over from page to page but the variables seem to get wiped out. Does this sound like a configuration thing or a code thing?
verifyuser.php
menu.php
The menu.php page print a session id but always printed "Not logged in" despite the var having been set to true in the verifyuser.php page. I've inherited most of this code but have been hacking away at it most of today trying to get it to work. Any ideas??
verifyuser.php
Code: Select all
<?php
session_start();
// Report simple running errors
error_reporting (E_ERROR | E_WARNING | E_PARSE);
$username = $_POST['username'];
$password = $_POST['password'];
$db_name = "CurtisDawe";
$table_name = "curtisdawe_admin";
$connection = @mysql_connect("localhost", "root", "pw") or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection) or die("Couldn't select database.");
$sql = "SELECT USERNAME, PASSWORD From $table_name WHERE username = \"$username\" AND password = \"$password\"";
$result = @mysql_query($sql,$connection) or die("Couldn't execute query.");
$num = mysql_num_rows($result);
If ($num > 0)
{
$_SESSION['loggedin'] = true;
header("Location: menu.php");
exit;
}
else
{
header("Location: index.php");
exit;
}
?>Code: Select all
<?php
session_start();
// Report simple running errors
error_reporting (E_ERROR | E_WARNING | E_PARSE);
print "Your session ID is: " . session_id();
if($_SESSION['loggedin']) echo "Logged in";
else echo "Not logged in";