Try these short scripts out to see if your sessions are indeed being created, variables passed and destroyed.
If these scripts are working then your problems lie within either the database structure or in your coding. Look for typo's, ;'s at the end of lines, etc.
You may need a session primer too. Unfortunately there are not very many well written tutorials on this subject on the net so I can't point you in the right direction. Hopefully you can find the errors and fix em on your own.
Here are three simple php pages. Name them as such: index.php, login.php and logout.php
PHP Code:
<?php
//index.php
?>
<title>Login Page</title>
<form action="login.php" method="post">
<table width="50%" border="0" align="center" cellpadding="3" cellspacing="3" bgcolor="#000000">
<tr>
<td width="58" valign="middle"> <font color="#FFFFFF" size="1" face="Arial, Helvetica, sans-serif">Username:</font></td>
<td width="138"> <input type="text" size="10" name="user"></td>
<td width="53"><font color="#FFFFFF" size="1" face="Arial, Helvetica, sans-serif">Password:</font></td>
<td width="118"> <input type="password" size="10" name="pass"></td>
<td width="202"> <input type="submit" name="submit" value="Log In"></td>
</tr>
</table>
</form>
PHP Code:
<?php
//login.php
// Start the login session
session_start();
// Retrieve the 'posted' variables and assign them to session variables
$_SESSION['user'] = $_POST['user'];
$_SESSION['pass'] = $_POST['pass'];
// Check to see if indeed there are session variables assigned
if (!$_SESSION['user'] || !$_SESSION['pass']) {
// If there are no session variables, we'll redirect them to the login form and kill the process.
header('Location: index.php');
die();
}else{
// Otherwise, this stuff gets printed out
echo "Sessions are working! You see? The variables travelled over these two pages.<br><br>";
echo "The username you entered was: " . $_SESSION['user'] . "<br>";
echo "The password you entered was: " . $_SESSION['pass'] . "<br>";
echo "If you have the session save path uncommented in your PHP.INI file,<br>that path on computer is: ";
print session_save_path();
echo "<br><br>Create this folder if it does not exist. Be sure to navigate to this folder to see if indeed a session is created.<br>Resize your Explorer window and browser window so they are both visible. <br>Then press the logout link below. Watch the session dissapear.<br>";
// Be sure to logout to kill the session. Examine the code on logout.php to see how this is done.
echo "<a href='logout.php'>Logout</a>";
}
?>
PHP Code:
<?PHP
//logout.php
session_start();
session_unset();
session_destroy();
header('Location: index.php');
?>
Bookmarks