如何销毁会话,以便无法返回

时间:2016-03-17 10:17:36

标签: php session

我正在注销我的网站,但我遇到了麻烦。如果我点击退出按钮,我会回到索引,如果我然后点击浏览器中的返回按钮,我会回到我登录的页面。我的问题是如何解除会话权限以防止这种情况发生发生。

如果有人登录,这是脚本:

    <?php
    session_start();
?>
    <html>
    <head>
        <link href="../css/style.css" rel="stylesheet" type="text/css">
        <link href='https://fonts.googleapis.com/css?family=Titillium+Web:400,300,200' rel='stylesheet' type='text/css'>
    </head>

    <body>
    <section class="photoContainer hero" data-stellar-background-ratio="0.5 ">
        <div class="content">
            <div class="hC">
                <h1>Presenting E-bike</h1>
                <h3>Why Pedal When You Don't have Too</h3>
            </div>
            <div class="panelContainer">
                <div class="panel3">
                    <div class="symbol2"></div>
                </div>
            </div>
            <div class="inlog">
                <a class="btn" href="../index.php">Log Out</a>
                <?php
                    session_destroy();
                ?>
            </div>
        </div>
    </section>

    <section class="wrapper">
        <div class="content">
            <h2>FAQ</h2>
            <p>This is where you will find the answers on the most frequently asked questions.</p><br />
            <p><b>Q:</b> What is a content management system?<br />
                <b>A:</b> A CMS is a web application you run on your web server to help creating a website. A good CMS should be flexible and help you to make a great site. It should provide you with tools to help the layman keep track of content, while letting more experienced webmasters handle look and feel. It should also provide tools to make repetitive things less repetitive. Like, for example, News entries.<br /><br />
            </p>
            <p><b>Q:</b> Why do I need a Web Content Management System? <br />
                <b>A:</b> If you have a website, you need to have some sort of CMS.  The more sophisticated your CMS, the more things you can do with your site.  <br /><br />
            </p>
            <p><b>Q:</b> Is prior web site development experience required to use a CMS? <br />
                <b>A:</b> No.  If you can use Microsoft Word you will have no trouble editing content on your website.  No HTML or coding is required. <br /><br />
            </p>
        </div>
    </section>

    <section class="photoContainer middle" data-stellar-background-ratio="0.5">
        <div class="content">
            <div class="panelContainer">
                <div class="panel2">
                    <div class="symbol3"></div>
                </div>
            </div>
        </div>
    </section>

    <section class="wrapper">
        <div class="content">
            <h2>This is how your title would look.</h2>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec facilisis tempus risus et tempor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In vehicula dui pretium magna sodales semper. Nunc faucibus mauris ante, in egestas urna tempus nec. Fusce rutrum est sit amet augue egestas gravida. Sed varius dui ac urna scelerisque euismod. Fusce mattis aliquam dolor at lobortis. Proin semper nulla ut nunc aliquam ultricies sed non nulla. Proin eleifend quis libero sed sodales. Mauris quis imperdiet sapien, quis facilisis orci.</p>
            <h4>This is how your subtitle would look.</h4><br />
            <p>Suspendisse potenti. Nunc mollis tellus ac dolor feugiat sagittis. Sed sit amet ex porta, dictum tellus quis, rhoncus arcu. Sed suscipit a orci at viverra. Integer non sem nec sem consequat efficitur et vitae dolor. Etiam dignissim dui in est porta congue quis id nulla. Integer tincidunt diam volutpat lacus finibus lobortis. Quisque ultricies scelerisque rhoncus.</p>
        </div>
    </section>

    <section class="photoContainer middle2" data-stellar-background-ratio="0.5 ">
        <div class="content">
            <div class="panelcontainer">
                <div class="panel1">
                    <div class="symbol"></div>

                </div>

            </div>
        </div>
    </section>

    <section class="wrapper">
        <div class="content">
            <h2>Contact</h2>
            <p>If you have any questions, or need more information, you will be able to contact us with the following information.</p>
            <br />
            <p>Telephone: (0800)12341833</p>
            <p>E-mail: <a href="../404.html">thebestcms@site.com</a></p>
            <p>Address: <a href="../404.html">GoogleMaps</a></p>
        </div>
    </section>

    <section>
        <div class="copyright">
            <p>Copyright &copy; 2016 1P6 Landstede - All rights reserved</p>
        </div>
    </section>

    <script src="../js/jquery-2.0.2.js"></script>
    <script src="../js/jquery.stellar.min.js"></script>
    <script>

        $.stellar();

    </script>
    </body>
    </html>

如果需要,我也会输入index.php

    <html>
<head>
    <link href="css/style.css" rel="stylesheet" type="text/css">
    <link href='https://fonts.googleapis.com/css?family=Titillium+Web:400,300,200' rel='stylesheet' type='text/css'>
</head>

<body>
<section class="photoContainer hero" data-stellar-background-ratio="0.5 ">
    <div class="content">
        <div class="hC">
            <h1>Presenting E-bike</h1>
            <h3>Why Pedal When You Don't have Too</h3>
        </div>
        <div class="panelContainer">
            <div class="panel3">
                <div class="symbol2"></div>
            </div>
        </div>
        <div class="inlog">
            <a class="btn" href="login/login.php">Login</a>
        </div>
    </div>
</section>

<section class="wrapper">
    <div class="content">
        <h2>FAQ</h2>
        <p>This is where you will find the answers on the most frequently asked questions.</p><br />
        <p><b>Q:</b> What is a content management system?<br />
            <b>A:</b> A CMS is a web application you run on your web server to help creating a website. A good CMS should be flexible and help you to make a great site. It should provide you with tools to help the layman keep track of content, while letting more experienced webmasters handle look and feel. It should also provide tools to make repetitive things less repetitive. Like, for example, News entries.<br /><br />
        </p>
        <p><b>Q:</b> Why do I need a Web Content Management System? <br />
            <b>A:</b> If you have a website, you need to have some sort of CMS.  The more sophisticated your CMS, the more things you can do with your site.  <br /><br />
        </p>
        <p><b>Q:</b> Is prior web site development experience required to use a CMS? <br />
            <b>A:</b> No.  If you can use Microsoft Word you will have no trouble editing content on your website.  No HTML or coding is required. <br /><br />
        </p>
    </div>
</section>

<section class="photoContainer middle" data-stellar-background-ratio="0.5">
    <div class="content">
        <div class="panelContainer">
            <div class="panel2">
                <div class="symbol3"></div>
            </div>
        </div>
    </div>
</section>

<section class="wrapper">
    <div class="content">
        <h2>This is how your title would look.</h2>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec facilisis tempus risus et tempor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In vehicula dui pretium magna sodales semper. Nunc faucibus mauris ante, in egestas urna tempus nec. Fusce rutrum est sit amet augue egestas gravida. Sed varius dui ac urna scelerisque euismod. Fusce mattis aliquam dolor at lobortis. Proin semper nulla ut nunc aliquam ultricies sed non nulla. Proin eleifend quis libero sed sodales. Mauris quis imperdiet sapien, quis facilisis orci.</p>
        <h4>This is how your subtitle would look.</h4><br />
        <p>Suspendisse potenti. Nunc mollis tellus ac dolor feugiat sagittis. Sed sit amet ex porta, dictum tellus quis, rhoncus arcu. Sed suscipit a orci at viverra. Integer non sem nec sem consequat efficitur et vitae dolor. Etiam dignissim dui in est porta congue quis id nulla. Integer tincidunt diam volutpat lacus finibus lobortis. Quisque ultricies scelerisque rhoncus.</p>
    </div>
</section>

<section class="photoContainer middle2" data-stellar-background-ratio="0.5 ">
    <div class="content">
        <div class="panelcontainer">
            <div class="panel1">
                <div class="symbol"></div>

            </div>

        </div>
    </div>
</section>

<section class="wrapper">
    <div class="content">
        <h2>Contact</h2>
        <p>If you have any questions, or need more information, you will be able to contact us with the following information.</p>
        <br />
        <p>Telephone: (0800)12341833</p>
        <p>E-mail: <a href="404.html">thebestcms@site.com</a></p>
        <p>Address: <a href="404.html">GoogleMaps</a></p>
    </div>
</section>

    <section>
        <div class="copyright">
            <p>Copyright &copy; 2016 1P6 Landstede - All rights reserved</p>
        </div>
    </section>

<script src="js/jquery-2.0.2.js"></script>
<script src="js/jquery.stellar.min.js"></script>
<script>

    $.stellar();

</script>
</body>
</html>

5 个答案:

答案 0 :(得分:2)

假设您正在使用pub_date = models.DateTimeField(default=datetime.now, blank=True) 来实际销毁会话,则问题不太可能是您的会话,问题可能是浏览器具有上一页的缓存版本。为了防止您需要设置适当的标题来指示浏览器不缓存您的身份验证页面,例如:

session_destroy()

有关血腥的详细信息,请参阅How to control web page caching, across all browsers?

答案 1 :(得分:1)

要在您的退出功能中销毁使用void session_unset ( void ),它将取消设置所有会话变量。 详情http://php.net/manual/en/function.session-unset.php

希望它有所帮助:)

答案 2 :(得分:0)

您收到此错误,因为浏览器正在从缓存加载页面。结果,没有向服务器发出请求。正如`pes502``在评论中指出的那样,如果你刷新页面请求将发送给服务器&amp;如果您拥有某种身份验证检查逻辑,则用户将被重定向到登录/您使用的任何页面。

我遇到过这个问题,我确实需要修复它。您可以使用将充当中间件的Ajax请求来检查用户是否已登录&amp;处理结果客户端而不是服务器端。

答案 3 :(得分:0)

而不是

<a class="btn" href="../index.php">Log Out</a>

只需使用名为logout.php的页面重定向

<?php ob_start();
    //Logs the user out
    session_start();
    unset($_SESSION['user_id']);
    session_destroy();

    header("Location: index.php");
    exit;
?>

答案 4 :(得分:-1)

您的退出功能在哪里?您是否尝试在注销功能中专门销毁会话?试试吧,告诉我结果。