Hey people,
im having trouble, i think with sessions.
I have the following script (member.php):
<?php
session_start();
$mysql_database="dbname";
$mysql_username="user";
$mysql_password="pass";
$dbconnect = mysql_connect("localhost",$mysql_username,$mysql_password) or die ("Unable to connect to SQL server");
mysql_select_db($mysql_database,$dbconnect) or die ("Unable to select database");
//create short variable names
$username = $_POST['username'];
$password = $_POST['password'];
// they have just tried logging in
if ($username && $password) {
// check if username is unique
$result = mysql_query("select * from users where username='$username' and password=sha1('$password')")
or die ("Could not log you in.");
if (mysql_num_rows($result)) {
$_SESSION['valid_user'] = $username;
}
else {
echo 'Login Failed. <br />[<a href=login.php>login</a>]';
exit;
}
}
echo 'Logged in as '.$_SESSION['valid_user'];
$user = $_SESSION['valid_user'];
$encPass = sha1($password);
$result = mysql_query("select * from users where username='$user'")
or die ("Couldn't Connect to Database.");
// now display the results returned
$row= mysql_fetch_array($result);
//Set result character limits
echo '<br><br><a href="'.$row['sitedir'].'/Admin/">Continue to '.$row['sitename'].'s Admin Area</a><br><br>';
include('member-menu.php');
?>
the script, makes sure the user is in the database and has the correct password and then it writes a link to that users admin area.
the page that the link takes the user to has a check on it to see if a session is open. this page is in a different directory to member.php.
I have the same check on a page which is in the same directory as member.php. - the trouble is this check works on this page but doesnt work on the page in the other directory.
this is my check code:
<?php
session_start();
$mysql_database="dbname";
$mysql_username="user";
$mysql_password="pass";
$dbconnect = mysql_connect("localhost",$mysql_username,$mysql_password) or die ("Unable to connect to SQL server");
mysql_select_db($mysql_database,$dbconnect) or die ("Unable to select database");
// check valid user
if (isset($_SESSION['valid_user'])) {
echo '<table width="250" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
<tr><td width="75"><b>User Status: </b></td>
<td bgcolor="#FFFFFF">Logged in as '.$_SESSION['valid_user'].'.</td>
</tr>
</table>';
}
else {
echo '<table width="250" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
<tr><td width="75"><b>User Status: </b></td>
<td bgcolor="#FFFFFF">You are not logged in.<br />[<a href=login.php>login</a>]</td>
</tr>
</table>';
exit;
}
?>
is there something that stops sessions working across directories?
any help is welcome,
Thanks.