[英]Refresh a page only once php
我在网站上使用PHP,并单击“说说myfile.php”,但我只希望页面刷新一次:代码如下:
<?php
if(called from myfile.php){
header(refresh:0);
}
Php code 1;
PHP code 2;
.
.
.
PHP code n;
?>
如何实现这种情况?
我不确定您要做什么,但我认为您将需要以下类似内容:
<?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>
我只是使用index.php进行测试。
您可以这样做:
if(empty($_GET['status'])){
header('Location:YourPagesPath.php?status=1');
exit;
}
如果不存在GET
参数,它将重新加载页面。
在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';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.