只刷新一次页面 php
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;
?>
如何实现这个场景?
在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>
我刚刚用了index.php来测试
你可以这样做:
if(empty($_GET['status'])){
header('Location:YourPagesPath.php?status=1');
exit;
}
如果 GET
参数不存在,这将重新加载页面。
我正在为我的网站使用 PHP 并点击说 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>
我刚刚用了index.php来测试
你可以这样做:
if(empty($_GET['status'])){
header('Location:YourPagesPath.php?status=1');
exit;
}
如果 GET
参数不存在,这将重新加载页面。