【问题标题】:Delay a redirection to show an html page for sometime延迟重定向以显示 html 页面一段时间
【发布时间】:2013-12-19 10:24:06
【问题描述】:

我有这个页面,它有一个重定向到另一个网站的 php。但是这也有一个 html,它将在重定向之前显示。可以在这里完成吗?我想延迟几个重定向seconds 表明 html 内容在页面被重定向之前显示了一段时间。

    <?php
            if($app_used=='Cnojhjkct')
            {
                $redirectTo=$respL."?status=".$status."&orderID=".$orderID."&transaefNo=".$cusf_no."&payMode=".$tranype."&cardider=".$cardPrider;
                header("Location: $redirectTo");
            }
    ?>


<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="A layout example with a side menu that hides on mobile, just like the Pure website.">

<title>Transaction Response</title>
<link rel="stylesheet" href="http://yui.yahooapis.com/pure/0.3.0/pure-min.css">
<link rel="stylesheet" href="./main.css">
</head>
<body>
<div id="layout">
    <div id="main">
           <div class="header">
             <div class="pure-g-r">
        <div class="pure-u-1-4">
         <img src="./gsggd.png" alt="Peyto Lake">
         </div></div>
           <h1>Transaction Response</h1> 
        </div>
       <div class="content">            
            </div>
                  <div style="width:100%">
       <div style="margin-left:5%;width:5%;float:left;margin-right:20%;"><img src="<?php
if($message == 'successfull')
{
    echo './success.png';
}
else
{
    echo './failed.png';
}
?>"/></div>
       <div style="width:70%;float:left;"><h3>Your transaction was <?php echo $message; ?> ! Your transaction reference number for any further communication is <?php echo $cust_ref_no; ?> .</h3></div>
   </div>
   </div>
   </div>     
    </div>
</div>
</body>
</html>

【问题讨论】:

标签: php html redirect url-redirection


【解决方案1】:

您不能使用 HTTP 位置重定向来延迟,因为一旦读取它就会重定向,
相反,您可以使用刷新重定向:

    header( "Refresh:5; url=$redirectTop", true, 303); 

【讨论】:

  • 你能告诉我这会做什么吗?是“5”延迟时间吗?还是刷新次数?
  • @user3105409 它会延迟刷新 5 秒,您可以根据需要更改它
【解决方案2】:

您不能使用“Location”标头重定向来执行此操作,因为它在发送后立即生效,并且必须在任何内容之前发送(即在重定向发生之前您无法显示任何内容)。

您最好的选择可能是刷新重定向。看到这个问题:How to Redirect Page in PHP after a few seconds without meta http-equiv=REFRESH CONTENT=time

或者,您可以使用客户端脚本来管理它(例如 Javascript)。理论上,这为您提供了最大的控制权,但在某些浏览器上可能会被禁用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-29
    • 1970-01-01
    • 2015-07-26
    • 2016-09-25
    • 2018-04-28
    • 2020-10-02
    相关资源
    最近更新 更多