防止浏览器后退按钮缓存 [英] prevent browser back button cache

查看:68
本文介绍了防止浏览器后退按钮缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我编写的代码

index.php:

index.php:

  <?php session_start(); 
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>
<!DOCTYPE html>
<html>
<head>
    <title>Student-login</title>
    <link href='http://fonts.googleapis.com/css?family=Shadows+Into+Light' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" type="text/css" href="css/main.css">
    <link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
    <link rel="shortcut icon" href="css/favicon.jpg"/>
    <link href='http://fonts.googleapis.com/css?family=Questrial' rel='stylesheet' type='text/css'>
</head>
<body>
    <div class="bodybg"></div>
    <div class="main-form">
        <h1>Student Login</h1>
        <form class="login" action="database.php" method="post">
            <input type="text" placeholder="&#xf007; User name(*)" name="username" required></input><br>
            <input type="password" placeholder="&#xf023; Password(*)" name="password" required>
        </input><br>
        <input type="submit" value="Login" name="btnlogin"></input><br>
        <div class="button"><a href="login.php">Register</a></div>

        <!--flash message-->
        <div id="message">
            <?php 
            if(isset($_SESSION['success'])){
                echo $_SESSION['success'];
                //echo "<p class='message'>hello this world!!</p>";

            }else{
                echo " ";
            }
            $_SESSION['success']=' ';
            ?>
        </div>
    </form>
</div>
<div id="heading">
    <p id="p1">American Internation University-Bangladesh</p>
    <p id="p2">Thesis Compilation</p>
</div>
<div id="content">
    <div id="prev"><i class="fa fa-chevron-left fa-1x"></i></div>
    <div id="next" d><i class="fa fa-chevron-right fa-1x"></i></div>
    <div id="pager"></div>
    <div id="slider">
        <div class="item">
            <img src="img/1.jpg">
            <div class="info">
                <h2>Picture 1</h2>
                <p>This is the library</p>
            </div>
        </div>
        <div class="item">
            <img src="img/2.jpg">
            <div class="info">
                <h2>Picture 2</h2>
                <p>This is the Book</p>
            </div>
        </div>
        <div class="item">
            <img src="img/3.jpg">
            <div class="info">
                <h2>Picture 3</h2>
                <p>This is the Pen</p>
            </div>
        </div>
        <div class="item">
            <img src="img/4.jpg">
            <div class="info">
                <h2>Picture 4</h2>
                <p>This is the literature</p>
            </div>
        </div>
        <div class="item">
            <img src="img/5.jpg">
            <div class="info">
                <h2>Picture 5</h2>
                <p>This is the Research</p>
            </div>
        </div>
    </div>  
</div>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/cycle.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>

和home.php:

 <?php 
session_start(); 
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Cache-Control: no-cache");
header("Pragma: no-cache");
?>
<!DOCTYPE html>
<html>
<head>
    <title>Home</title>
    <link href='http://fonts.googleapis.com/css?family=Shadows+Into+Light' rel='stylesheet'
    type='text/css'>
    <link rel="stylesheet" type="text/css" href="css/main.css">
    <link rel="stylesheet" type="text/css" href="css/font-awesome.min.css">
    <link rel="shortcut icon" href="css/favicon.jpg"/>
</head>
<body class="body"> 

    <div class="menu">
        <div class="home">
            <a href="Home.html">Home</a>
        </div>
        <div class="profile">
            <a href="profile.html">Profile</a>
        </div>
        <div class="contact">
            <a href="contact.html">Contact</a>
        </div>
        <div class="logout">
            <a href="database.php?laction">Logout</a>
        </div>
    </div>
    <div class="transparent">
    </div>
    <div class="content">
        <div id="message">
            <?php 
            if(isset($_SESSION['success'])){
                echo $_SESSION['success'];
                //echo "<p class='message'>hello this world!!</p>";

            }else{
                echo " ";
            }
            $_SESSION['success']=' ';
            ?>
        </div>
    </div>
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript" src="js/main.js"></script>
</body>
</html>

,问题是这应该可以防止通过header()函数在浏览器中进行缓存,但是在加载页面后,后退按钮会将我带到上一页,浏览器的前进按钮会将我带到下一页谁能帮忙防止该浏览器缓存,或者为什么我的代码在这里无法正常工作?

and the problem is this should have prevent the cache in the browser through header() function but after loading the page the back button is taking me to the previous page and the forward button of the browser is taking me to the next page can any one help how to prevent this browser cache or why is my code here is not working?

推荐答案

感谢大家的帮助,但我找到了一种方法,可以强制浏览器阻止缓存,并且我使用了以下代码:

Thanks guys for helping me out but i found a way that force the browser to prevent cache and i have used the below code :

header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0 "); // Proxies.

这里是参考: 确保跨网页未缓存网页所有浏览器 而且效果很好.

here is the reference : Making sure a web page is not cached, across all browsers and its working pretty good.

这篇关于防止浏览器后退按钮缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆