簡體   English   中英

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;
?>

如何實現這種情況?

我不確定您要做什么,但我認為您將需要以下類似內容:

<?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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM