[英]Refresh a page only once php
I am using PHP for my website and clicked from say myfile.php I want the page to be refreshed only once: The code would be like: 我在网站上使用PHP,并单击“说说myfile.php”,但我只希望页面刷新一次:代码如下:
<?php
if(called from myfile.php){
header(refresh:0);
}
Php code 1;
PHP code 2;
.
.
.
PHP code n;
?>
How to achieve this scenario? 如何实现这种情况?
I don't exactly understand what you are trying to do, but I think you will need something similar to this: 我不确定您要做什么,但我认为您将需要以下类似内容:
<?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>
I just used index.php for testing. 我只是使用index.php进行测试。
You could do: 您可以这样做:
if(empty($_GET['status'])){
header('Location:YourPagesPath.php?status=1');
exit;
}
Which would reload the page and if the GET
parameter isn't present. 如果不存在GET
参数,它将重新加载页面。
In myfile.php
set a session variable 在myfile.php
设置一个会话变量
session_start();
$_SESSION['calledFrom'] = 'myfile.php';
and check for it in this file 并在此文件中检查
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.