这是我写的代码
的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=" User name(*)" name="username" required></input><br>
<input type="password" placeholder=" 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()函数阻止浏览器中的缓存但是在加载页面后,后退按钮将我带到上一页,浏览器的前进按钮将我带到下一页任何人都可以帮助如何防止这个浏览器缓存或为什么我的代码不起作用?
答案 0 :(得分:9)
感谢大家帮助我,但我发现了一种强制浏览器阻止缓存的方法,我使用了以下代码:
header("Cache-Control: no-cache, no-store, must-revalidate"); // HTTP 1.1.
header("Pragma: no-cache"); // HTTP 1.0.
header("Expires: 0 "); // Proxies.
这里是参考: Making sure a web page is not cached, across all browsers 它的工作非常好。