Php 只刷新一次页面

Php 只刷新一次页面,php,refresh,Php,Refresh,我在我的网站上使用PHP,并从say myfile.PHP单击我希望页面只刷新一次: 代码如下所示: <?php if(called from myfile.php){ header(refresh:0); } Php code 1; PHP code 2; . . . PHP code n; ?> 如何实现此场景?在myfile.php中设置会话变量 session_start(); $_SESSION['calledFrom'] = 'myfile.php'; 并

我在我的网站上使用PHP,并从say myfile.PHP单击我希望页面只刷新一次: 代码如下所示:

<?php 
 if(called from myfile.php){
 header(refresh:0);
 }
Php code 1;
PHP code 2;
.
.
.
PHP code n;
?>


如何实现此场景?

myfile.php
中设置会话变量

session_start();
$_SESSION['calledFrom'] = 'myfile.php';
并在这个文件中检查它

session_start();
if(isset($_SESSION['calledFrom'])) && 'myfile.php' == $_SESSION['calledFrom']) {
    $_SESSION['calledFrom'] = 'thisfile.php';
    header("Refresh:0");
} else {
    $_SESSION['calledFrom'] = 'thisfile.php';
}

我不太明白你想做什么,但我认为你需要类似的东西:

<?php
if( isset( $_GET["caller"] ) && $_GET["caller"] == "somevalue" ) {
    // I'm using Location because this will remove the get value
    header( "Location: index.php" );
    exit;
}
?>
<a href="index.php">just go to index</a><br/>
<a href="index.php?caller=somevalue">got to index and refresh?</a>
您可以执行以下操作:

if(empty($_GET['status'])){
     header('Location:YourPagesPath.php?status=1');
     exit;
}

如果
GET
参数不存在,它将重新加载页面。

我不想一直设置会话变量,否则每次设置会话变量后它都会这样做。这就是第二个条件(
'myfile.php'=$\u session['calledFrom']
)的作用。(空($\u GET['status']))我不工作,因为我必须向该变量传递不同的值。您可以传递不同的值,而不使用
empty
,这只是一个简单的示例。看起来你已经开始工作了,不是吗?