簡體   English   中英

PHP Logout不會在用戶注銷時從用戶所在的頁面中注銷用戶

[英]PHP Logout won't log user out from the page the user was on, when they logged out

我有一個帶有登錄和注銷的PHP站點,使用$_SESSION['userName']來存儲登錄成員的username

但是當人們登錄時,由於某種原因,這不會立即發生。 與Logout腳本相同:它有效,但不是立即。 在發生事情之前我必須嘗試2-4次。

這是我的登錄代碼和注銷代碼:

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

我真的希望你能幫我解決這個問題。 登錄工作正常,注銷可以將用戶從所有頁面中記錄下來EXEPT用戶所在的頁面,當他們點擊“注銷”時...任何想法?

用以下行替換logout.php中所有與會話相關的函數:

session_start();
session_destroy();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM