【问题标题】:logout.php does not session_destroylogout.php 没有 session_destroy
【发布时间】:2014-07-20 04:23:46
【问题描述】:

logout.php 我的问题但也许不是Logout.php 绝对有效。当用户登录然后他点击注销按钮logout.php重定向index.php

我的index.php 是登录和注册页面。当用户登录 index.php 重定向 main.php ,然后当用户单击注销用户重定向 index.php 它仍然有效。 Hoverwer 如果用户在用户注销 url 后输入 url http://www.example.com/main.php 表示您仍然登录。

index.php代码

<?php
ob_start("ob_gzhandler");
error_reporting(0);
include_once 'includes/db.php';
include_once 'includes/User.php';
session_start();
$session_uid=$_SESSION['uid']; 
if(!empty($session_uid))
{
    header("location:main.php");
}

$User = new User();

//Login
$login_error='';
if($_POST['user'] && $_POST['passcode'] )
{
    $username=$_POST['user'];
    $password=$_POST['passcode'];
    if (strlen($username)>0 && strlen($password)>0)
    {
        $login=$User->User_Login($username,$password);

        if($login)
        {
            $_SESSION['uid']=$login;
            header("Location:main.php");
        }
        else
        {
        $login_error="<span class='error'>Wrong password or username!</span>";
        }
    }
}

//Registration
$reg_error='';
if($_POST['email'] && $_POST['username'] && $_POST['password'] )
{
    $email=$_POST['email'];
    $username=$_POST['username'];
    $password=$_POST['password'];

    if (strlen($username)>0 && strlen($password)>0 && strlen($email) )
    {
        $reg=$User->User_Registration($username,$password,$email);

        if($reg)
        {
            $_SESSION['uid']=$reg;
            header("Location:main.php");
        }
        else
        {
            $reg_error="<span class='registererror'>Username or Email is already exists.</span>";
        }


    }
}

?>

session.php代码

 <?php
$session_uid=$_SESSION['uid']; 
// Session Private
if(!empty($session_uid))
{
    $uid=$session_uid;
    $login='1';
}
else if($_GET['username'] || $_GET['msgID'])
{
    $uid=$Wall->User_ID($username);
    $login='0';
}
else
{
    $url=$base_url.'index.php';
    header("location:$url");
}

?>

logout.php代码

 <?php
error_reporting(0);
session_start();
$_SESSION['uid']=''; 
if(session_destroy())
{
    $url=$base_url.'index.php'; 
    //header("Location: $url");
    echo "<script>window.location='$url'</script>";
}
?>

我做错了什么或错过了什么。请帮助我...对不起我的英语:(

【问题讨论】:

  • 你应该清除会话数据,以便在注销后,如果用户打印 main.php,它应该显示主页,而不是真正的主页。

标签: php session


【解决方案1】:

logout.php试试这个代码:

<?php 
   session_start();
    session_destroy();
    header('Location: index.php');
?>

【讨论】:

    【解决方案2】:

    尝试这样做:

    unset($_SESSION['uid']);
    

    【讨论】:

    • 我试了一下,但现在当我点击logout.php页面重定向我main.php
    • 这就是 index.php 中的代码告诉它要做的事情。
    【解决方案3】:

    session.php 中你没有启动会话:

    session_start();
    

    【讨论】:

      猜你喜欢
      • 2018-05-16
      • 2012-01-28
      • 2012-11-01
      • 2017-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2013-04-03
      相关资源
      最近更新 更多