本文介绍了如何在用户按下注销并销毁会话后禁用后端浏览器按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到 session_destroy()的麻烦。

当用户按注销时,必须销毁会话。我写了下面的代码:

Logout.php

 <?php 
session_start();
session_destroy();
header(location:LoginViewController.php);
?>

按下退出后,当我按下浏览器后退按钮时,在 Login.php 页面中显示我以前的Logined用户页面和会话用户名


$ b

Login.php

 <?php 
session_start();
$ _SESSION ['user'] = $ _GET ['username'];
echo'< div style =background:white; text-align:right>登录为:'。$ _ SESSION ['user']。'< / div>'';
echo'< a href =Logout.phpstyle =text-align:right>注销< / a>';

LoginViewController.php

 <?php 
header(Cache-Control:no-store,no-cache,must-revalidate,max-age = 0\" );
标题(过期:星期六,1997年7月26日05:00:00 GMT);

$用户名= $ _POST ['uname'];
$ Password = $ _POST ['pwd'];
$ User_Type = $ _ POST ['type'];如果(!(空($用户名)&&空($密码)&&空($ User_Type))){
$ model = new UsersModel();


$ rowsCount = $ model-> checkUser($ Username,$ Password,$ User_Type);
$ b $ if($ rowsCount!= 0){
header(location:login.php?username =。$ _ POST ['uname']。);
} else {
echo'< script type =text / javascript> alert(正确输入用户名和密码);
window.location.href =LoginViewController.php;< / script>';
}
}

我不知道它为什么会这样工作。
请帮助我找出我犯的错误。



我想在注销后禁用浏览器后退按钮。

解决方案

login.php页面:

 < ;?php 
if(isset($ _ POST ['uname'],$ _POST ['pwd'],$ _POST ['type'])){
$ Username = $ _POST ['uname' ]。
$ Password = $ _POST ['pwd'];
$ User_Type = $ _ POST ['type'];
if(!(empty($ Username)|| empty($ Password)|| empty($ User_Type)))
{
$ model = new UsersModel();
$ rowsCount = $ model-> checkUser($ Username,$ Password,$ User_Type);
if($ rowsCount!= 0)
{
$ _SESSION ['user'] = $用户名;
header(Location:LoginViewController.php);

} else {
echo'Bad user';
}
} else {
echo'请填写所有输入';
}
} else {
echo'Bad form sent';
}
?>
< form name =f1method =POSTaction =>
//输入
< / form> b


$ b

LoginViewController.php: > <?php
header(Cache-Control:no-store,no-cache,must-revalidate,max-age = 0);
标题(过期:星期六,1997年7月26日05:00:00 GMT);
$ b $ if(!isset($ _ SESSION ['user'])){
header('Location:login.php');
exit();
}
echo'您已成功记录为'。$ _ SESSION ['user']
?>

然后添加标题以强制浏览器重新验证页面:



logout.php:

 <?php 
session_start();
session_destroy();
$ _SESSION = array();
header(location:login.php);
?>


I am having trouble with session_destroy().
When the User press Log out it have to destroy the session. I wrote the following code:

Logout.php

<?php
    session_start();
    session_destroy();
    header("location: LoginViewController.php");
?>

After pressing log out, when I press the browser back button it is showing my previous Logined user page and session username in Login.php page

Login.php

<?php
    session_start();
    $_SESSION['user']=  $_GET['username'];
    echo '"<div style="background:white; text-align:right"> Login as:'.$_SESSION['user'].'</div>"';
    echo '<a href="Logout.php" style="text-align:right">Logout</a>';

LoginViewController.php

<?php
    header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

    $Username = $_POST['uname'];
    $Password = $_POST['pwd'];
    $User_Type=$_POST['type'];

    If (!(empty($Username) && empty($Password) && empty($User_Type))){
        $model = new UsersModel();
        $rowsCount = $model->checkUser($Username,$Password,$User_Type);

        if ($rowsCount!=0){
            header("location:login.php?username=".$_POST['uname']."");
        } else {
            echo '<script type="text/javascript">alert("Enter username and password correctly");
            window.location.href="LoginViewController.php";</script>';
        }
    }

I don't know why it is working like that.
Please help me to find out where i commit mistake.

I want to disable that browser back button after logout.

解决方案

login.php page :

<?php
    if (isset($_POST['uname'], $_POST['pwd'], $_POST['type'])) {
        $Username = $_POST['uname'];
        $Password = $_POST['pwd'];
        $User_Type=$_POST['type'];
        if (!(empty($Username) || empty($Password) || empty($User_Type)))
        {
             $model = new UsersModel();
             $rowsCount = $model->checkUser($Username,$Password,$User_Type);
             if ($rowsCount!=0)
             {
                  $_SESSION['user'] = $Username;
                  header("Location:LoginViewController.php");

             } else {
                  echo 'Bad user';
             }
        } else {
             echo 'Please, fill all inputs';
        }
    } else {
        echo 'Bad form sent';
    }
?>
<form name="f1" method="POST" action="" >
    // inputs
</form>

LoginViewController.php :

<?php
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

if (!isset($_SESSION['user'])) {
    header('Location: login.php');
    exit();
}
echo 'You have successfully logged as '.$_SESSION['user']
?>

And add the headers to force the browser to revalidate the pages :

logout.php :

<?php
session_start();
session_destroy();
$_SESSION = array();
header("location: login.php");
?>

这篇关于如何在用户按下注销并销毁会话后禁用后端浏览器按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 06:32