2013-06-19 31 views
0

我有一個使用登錄和註銷的PHP站點,使用$_SESSION['userName']來存儲登錄成員的usernamephp註銷無法將用戶從他們登出的頁面登出

登錄工作,註銷可以將用戶從所有頁面中註銷EXEPT用戶所在的頁面,當他們點擊「註銷」時......任何想法?

這裏是我的登錄密碼和註銷碼:

代碼:/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"); 

我真的希望你能幫助我與這個問題。

+0

您沒有提供 '用戶名' 使用'session_start'和'session_unset'時 – Sietse

+0

1)開始使用的mysqli http://www.php.net/mysqli 2)您可能要添加這將使用session_start()重置會話數組'$ _SESSION = array();'和ofcourse開始頁面;'' – Grmn

回答

0

我假設您在腳本中有一些代碼來檢查用戶名會話是否已設置。

session_start(); 
$_SESSION['userName'] =''; 
session_unset(); 
session_destroy(); 
header("Location: index.php"); 
相關問題