Question

I'm working on a flight booking website. I've to make a load page with the search first, after 3 sec i want to redirect the request to another php page.

Code i tried:

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

But it seems didn't work in my case. Redirecting immediately without displaying any thing. any ideas ?

Was it helpful?

Solution

you can redirect using a meta-tag:

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

or

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

you can place meta-refresh in browser-body and it will still refresh the site (this might be considered bad html coding) the number after content=" defines the seconds to wait before redirecting. in your case:

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']."\">";
}

note: setting url like URL=foo.bar in page.php will redirect to page.phpfoobar, so you might want to use a / or . prefix

I hope this helped you :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top