0

我在一个航班预订网站上工作。我必须先用搜索创建一个加载页面,3 秒后我想将请求重定向到另一个 php 页面。

我试过的代码:

<?php
    ob_start();
    $date = new DateTime($_REQUEST['departuredate']);
    if($_REQUEST['type'] == "ROUND"){
        $adate = new DateTime($_REQUEST['arrivaldate']);
    }
    date_default_timezone_set('Asia/Kolkata');

    $dcn = explode("-", $_REQUEST['departure']);
    $acn = explode("-", $_REQUEST['arrival']);

    $departure = substr(strstr($_REQUEST['departure'],'['), 1, 3);
    $arrival = substr(strstr($_REQUEST['arrival'],'['), 1, 3);
?>
<html>
    <head>
        <?php
            if($_REQUEST['type'] == "ONE"){
                echo "<title>".trim($dcn[1])." &#8594; ".trim($acn[1])." on ".date_format($date, 'D d, M Y')."</title>";
            }else if($_REQUEST['type'] == "ROUND"){
                echo "<title>".trim($dcn[1])." &#8594; ".trim($acn[1])." &#8594 ".trim($dcn[1])." on ".date_format($adate, 'D d, M Y')."</title>";
            }
        ?>
        <style>
            body{
                text-align:center;
                font-family:'WOL_Reg','Segoe UI',Tahoma,Helvetica,sans-serif;
            }
            img{
                border:0 none;
                vertical-align:middle;
            }
            table{
                border:1px solid #bcbcbc;
                border-radius:3px;
                box-shadow:0px 0px 3px inset #bcbcbc;
                text-align:center;
            }
            .nomargin{
                margin:0px;
                padding:0px;
            }
            .first{
                background-color:#bcbcbc;
                color:#fff;
                font-weight:600;
                text-align:left;
            }
            td{
                text-align:left;
                border-right:1px solid #bcbcbc;
                font-size:12px;
            }
            .reasons2{
                font-size:12px;
                margin:50px 0;
                text-align:center;
            }
            .reasons2 span{
                color:#F68500;
                font-weight:600;
            }
        </style>
    </head>
    <body>
        <p class='nomargin'><img src='images/logo.gif' alt='Geeglobia' /></p>
        <p><img src='images/loading.gif' alt='Loading...' /></p>
        <p>Loading.... Please do not close this window</p>
        <table cellspacing='0' cellpadding='5' width='30%' border='0' align='center'>
            <tr class='first'>
                <td>From</td>
                <td>To</td>
                <td>Date</td>
            </tr>
            <tr>
                <td><?php echo trim($dcn[1])." [".$departure."]"; ?></td>
                <td><?php echo trim($acn[1])." [".$arrival."]"; ?></td>
                <td><?php echo date_format($date, 'D d, M Y'); ?></td>
            </tr>
            <?php if($_REQUEST['type'] == "ROUND"){ ?>
            <tr>
                <td><?php echo trim($acn[1])." [".$arrival."]"; ?></td>
                <td><?php echo trim($dcn[1])." [".$departure."]"; ?></td>
                <td><?php echo date_format($adate, 'D d, M Y'); ?></td>
            </tr>
            <?php } ?>
        </table>
        <p class='reasons2'><span>Reasons to book with us ? &nbsp; &nbsp; </span><img alt='Tick' src='images/tick.jpg'> Lowest price promise &nbsp; &nbsp; <img alt='Tick' src='images/tick.jpg'> Expert travel advise &nbsp; &nbsp; <img alt='Tick' src='images/tick.jpg'> 24X7 travel support</p>
    </body>
</html>
<?php
    ob_end_clean();
    if($_REQUEST['stype'] == "INTL"){
        header("Location: isearch.php?".$_SERVER['QUERY_STRING']);
    }else{
        header("Location: search.php?".$_SERVER['QUERY_STRING']);
    }
    ob_end_flush();
?>

但在我的情况下似乎不起作用。立即重定向而不显示任何内容。有任何想法吗 ?

4

1 回答 1

1

您可以使用元标记重定向:

html: <meta http-equiv="refresh" content="3; URL=/urlgoeshere.url">

或者

php: echo "<meta http-equiv=\"refresh\" content=\"3; URL=/urlgoeshere.url\">";

您可以在浏览器正文中放置元刷新,它仍然会刷新网站(这可能被认为是糟糕的 html 编码) content=" 之后的数字定义了重定向之前要等待的秒数。在您的情况下:

if($_REQUEST['stype'] == "INTL"){
echo "<meta http-equiv=\"refresh\" content=\"3; URL=/isearch.php?".$_SERVER['QUERY_STRING']."\">";
}else{
echo "<meta http-equiv=\"refresh\" content=\"3; URL=/search.php?".$_SERVER['QUERY_STRING']."\">";
}

注意:在 page.php 中设置 URL=foo.bar 之类的 URL 将重定向到 page.phpfoobar,因此您可能需要使用 / 或 . 字首

我希望这对你有帮助:)

于 2014-02-24T08:11:36.007 回答