我有一个 logout.php 链接,如果用户单击它应该将它们注销。
<?php
// logout.php
// you must start session before destroying it
session_start();
session_unset();
session_destroy();
//}
//echo "You have been successfully logged out.
?>
但是,当我返回 login.php 时,它会在 login.php 之后自动将它们重定向到登录页面。下面是 login.php 的代码
<?php
// Connects to your Database
mysql_connect("localhost", "root", "") or die( mysql_error() );
mysql_select_db("sales") or die( mysql_error() );
//Checks if there is a login cookie
if( isset( $_COOKIE['ID_my_site'] ) ) {
//if there is, it logs you in and directes you to the members page
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'") or die( mysql_error() );
while( $info = mysql_fetch_array( $check ) ) {
if ( $pass != $info['password'] ) {
} else {
header("Location: sales.php");
}
}
}
// if login is ok then we add a cookie
$_POST['username'] = stripslashes($_POST['username']);
$hour = time() + 3600;
setcookie( ID_my_site, $_POST['username'], $hour );
setcookie( Key_my_site, $_POST['pass'], $hour );
//then redirect them to the members area
header("Location: sales.php");