我正在航班预订网站上工作。我首先使用搜索创建一个加载页面,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])." → ".trim($acn[1])." on ".date_format($date, 'D d, M Y')."</title>";
}else if($_REQUEST['type'] == "ROUND"){
echo "<title>".trim($dcn[1])." → ".trim($acn[1])." → ".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 ? </span><img alt='Tick' src='images/tick.jpg'> Lowest price promise <img alt='Tick' src='images/tick.jpg'> Expert travel advise <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();
?>
但似乎在我的案例中并没有起作用。立即重定向而不显示任何内容。任何想法?
答案 0 :(得分: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会重定向到page.phpfoobar,因此您可能需要使用/或。前缀
我希望这有助于你:)