Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 重定向将显示包含过时信息的页面_Php - Fatal编程技术网

Php 重定向将显示包含过时信息的页面

Php 重定向将显示包含过时信息的页面,php,Php,我有一个角色创建表单,您可以在其中输入角色名称,然后按submit。然后会出现一个成功页面。但是,我不希望用户能够使用返回按钮返回到角色创建页面,因此在角色创建页面上,如果检测到引用页面是成功页面,我将重定向到主菜单页面。但是,当它打开主菜单页面时,显示的信息已过时。您必须刷新页面才能使其反映最新的更改。这几乎就好像重定向正在打开页面的缓存版本 你知道为什么最新的更改没有显示在重定向上吗 <?php // First we execute our common code to conn

我有一个角色创建表单,您可以在其中输入角色名称,然后按submit。然后会出现一个成功页面。但是,我不希望用户能够使用返回按钮返回到角色创建页面,因此在角色创建页面上,如果检测到引用页面是成功页面,我将重定向到主菜单页面。但是,当它打开主菜单页面时,显示的信息已过时。您必须刷新页面才能使其反映最新的更改。这几乎就好像重定向正在打开页面的缓存版本

你知道为什么最新的更改没有显示在重定向上吗

<?php 

// First we execute our common code to connection to the database and start the session 
define('MyConst', TRUE);

include('database.class.php');
include('table.class.php'); 
include('user.class.php');
include('loginattempts.class.php');
include('timer.class.php'); 
include('functions.php'); 
include('loginf.php');
include('character.class.php');
include('playercharacter.class.php');

$dbo = database::getInstance();
$dbo -> connect("***********", "********", "*********", "********", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); 

secSessionStart();

// At the top of the page we check to see whether the user is logged in or not 
if(empty($_SESSION['user'])) 
{ 
    // If they are not, we redirect them to the login page. 
    header("Location: login.php"); 

    // Remember that this die statement is absolutely critical.  Without it, 
    // people can view your members-only content without logging in. 
    die("Redirecting to login.php"); 
} 

// Everything below this point in the file is secured by the login system 
if($_SERVER['HTTP_REFERER'] == "success.php") {
    // If they are not, we redirect them to the login page. 
    header("Location: mainmenu.php"); 

    // Remember that this die statement is absolutely critical.  Without it, 
    // people can view your members-only content without logging in. 
    die("Redirecting to mainmenu.php");
} 
if(!empty($_POST)) {

    $character = new character();
    $data = array("character_name" => $_POST['charactername'], "health" => 0, "money" => 1500, "exp" => 0, "rank" => 0, "points" => 0); 
    $character -> bind($data);
    $character -> store();
    $character_id = $dbo -> getConnection() -> lastInsertId();

    $playercharacter = new playercharacter();
    $data = array("character_id" => $character_id, "user_id" => $_SESSION['user']['user_id']);
    $playercharacter -> bind($data);
    $playercharacter -> store();

    $query = "SELECT * FROM playercharacter WHERE character_id = :character_id"; 

    try { 
        $stmt = $dbo->getConnection()->prepare($query); 
        $result = $stmt->execute(array(':character_id'=>$row['character_id'])); 
    } 
    catch(PDOException $ex) { 
        die("Failed to run query4: " . $ex->getMessage()); 
    }

    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    $_SESSION['playercharacter'] = $row;

    // If they are not, we redirect them to the login page. 
    header("Location: success.php"); 

    // Remember that this die statement is absolutely critical.  Without it, 
    // people can view your members-only content without logging in. 
    die("Redirecting to success.php");    
 }         
?>

<!DOCTYPE HTML>
<head>
<meta http-equiv="content-type" content="text/html" />
<meta name="author" content="lolkittens" />

<title>Untitled 5</title>
</head>

 <body> 
<h1>Create Character</h1> 
<form action="createcharacter.php" method="post"> 
    Enter name:<br /> 
    <input type="text" name="charactername" value="" /> 
    <br /><br /> 
    <input type="submit" value="Create" /> 
</form> 
</body>

无标题5
塑造人物
输入名称:


createcharacter.php

<?php 

// First we execute our common code to connection to the database and start the session 
define('MyConst', TRUE);

include('database.class.php');
include('table.class.php'); 
include('user.class.php');
include('loginattempts.class.php');
include('timer.class.php'); 
include('functions.php'); 
include('loginf.php');

$dbo = database::getInstance();
$dbo -> connect("*************", "*********", "**********", "***********", array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8')); 

secSessionStart();

// At the top of the page we check to see whether the user is logged in or not 
if(empty($_SESSION['user'])) 
{ 
    // If they are not, we redirect them to the login page. 
    header("Location: login.php"); 

    // Remember that this die statement is absolutely critical.  Without it, 
    // people can view your members-only content without logging in. 
    die("Redirecting to login.php"); 
} 

// Everything below this point in the file is secured by the login system 

// We can display the user's username to them by reading it from the session array.  Remember that because 
// a username is user submitted content we must use htmlentities on it before displaying it to the user. 

 ?>
 <!DOCTYPE html>
 <html>
 <head>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
  </script>  
 </head>
 <body>
 <a href="mainmenu.php">Success!</a></a>

  </body>
  </html>

线路

if($_SERVER['HTTP_REFERER'] == "success.php") 
永远不会是真的
$\u服务器['HTTP\u REFERER']
(设置时)包含URL,而不是文件名。因此,继续执行。如果执行(!empty($\u POST)){
并将用户重定向到success.php,则显示HTML代码或以
开头的块

成功设置会话变量将获得更好的结果。设置该变量后,重定向到mainmenu.php。或者,您可以在重定向语句中使用URL参数:

header("Location: success.php?complete=yes")
然后像这样检查它:

if ($_GET['complete'] == 'yes') {
   // Redirect to the main menu

把代码放在plz上,看起来像是一个缓存页面的问题。
if ($_GET['complete'] == 'yes') {
   // Redirect to the main menu