0

我有一个带有登录和注销的 PHP 站点,$_SESSION['userName']用于存储username已登录成员的登录信息。

登录有效,注销可以将用户从所有页面中注销,当用户单击“注销”时,用户所在的页面除外……有什么想法吗?

这是我的登录代码和注销代码:

代码:/login.php

session_start();
//=============Configuring Server and Database=======
$host        =    'host';
$user        =    'username';
$password    =    'password';
//=============Data Base Information=================
$database    =    'database';

$conn        =    mysql_connect($host,$user,$password) or die('Server Information 
is not Correct'); //Establish Connection with Server
mysql_select_db($database,$conn) or die('Database Information is not correct');

//===============End Server Configuration============

//*******Form Information********

$userName=mysql_real_escape_string($_POST['username']); 
$password=mysql_real_escape_string($_POST['password']); 
$passWord=md5($password); // Encrypted Password

//*********retrieving data from Database**********

$query = "select * from users where userName='$userName' and passWord='$passWord'";

$res = mysql_query($query);

$rows = mysql_num_rows($res);

//**********if $userName and $passWord will match database, The above function 
//**********will return 1 row

if($rows==1)

//***if the userName and password matches then register a session and redrect 
//***user to the Successfull.php
{
    $_SESSION['userName'] = $userName;
    header("location: ../index.php");
}
else
{
    echo 'Incorrect username or password.';
}
exit;

代码:/logout.php

session_name('userName');
session_start('userName');
session_unset('userName');
session_destroy();
header("Location:index.php");

我真的希望你能帮助我解决这个问题。

4

1 回答 1

0

我假设您的脚本中有一些代码来检查用户名会话是否已设置。

session_start();
$_SESSION['userName'] ='';
session_unset();
session_destroy();
header("Location: index.php");
于 2013-06-19T16:18:24.817 回答