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


How to destroy a session so no return is possible

我正在注销我的网站,但我遇到了问题。如果我点击注销按钮,我会返回索引,如果我点击浏览器中的返回按钮,我会回到我登录的页面。我的问题是,我如何正确结束会议以防止这种情况发生。

如果有人登录,下面是脚本:

    <?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>

如果需要,我也会输入索引.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>

假设您使用session_destroy()实际销毁会话,问题不太可能是您的会话,问题可能是浏览器具有上一页的缓存版本。为了防止这种情况,您需要设置适当的标头来指示浏览器不要缓存经过身份验证的页面,如下所示:

Cache-Control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0

请参阅如何在所有浏览器中控制网页缓存?了解血腥细节。

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

希望对:)有所帮助

您收到此错误是因为浏览器正在从缓存加载页面。因此,不会向服务器发出任何请求。正如"pes502"在评论中指出的那样,如果您刷新页面,将发送对服务器的请求,并提供某种身份验证检查逻辑,用户将被重定向到登录/您使用过的任何页面。

遇到了这个问题,我确实需要修复它。您可以使用Ajax请求作为中间件来检查用户是否已登录并处理结果客户端而不是服务器端。

而不是

<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;
?>

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