我的网站使用PHP,并从say myfile.PHP中单击。我希望页面只刷新一次:代码如下:
<?php
if(called from myfile.php){
header(refresh:0);
}
Php code 1;
PHP code 2;
.
.
.
PHP code n;
?>
如何实现这种情况?
你可以做:
if(empty($_GET['status'])){
header('Location:YourPagesPath.php?status=1');
exit;
}
如果GET
参数不存在,则会重新加载页面。
我不完全理解你想做什么,但我认为你需要类似的东西:
<?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进行测试。
在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';
}