我有一个 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");
最佳答案
Cookie 和 session 不是同一件事(尽管后者通常由存储在 Cookie 中的标识符支持)。
在 cookie 中存储用户名和密码是一个糟糕的主意。请改用 $_SESSION
。
关于php - Logout.php 不会破坏 cookie 或登录名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17462816/