crecy
crecy

Reputation: 29

Redirect to a URL, once the page is created

I want to present the user with a holding page that is replaced with the index.html page of a new website once the website has been created.

At the moment, I can only do it by having a timed refresh.

<?php
//DB connection and posting 

$location="http://" . $id;
header("refresh: 240; url=$location");
?>

<?
ob_start(); 
?> 

..... HTML code of holding page

<? 
echo ob_get_clean();
?>

Slightly out of my depth with this but have tried putting the holding page code at the beginning of the code and then inserting the following code at the end to validate the index.html file. But no luck . Any help much appreciated

<?
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $location);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);

start:
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if ($retcode == "200")
    {
     header("url=$location");
    }   
else
    {
        sleep(5);
    goto start;
    }
?>

Upvotes: 2

Views: 151

Answers (2)

Ganesh Rathinavel
Ganesh Rathinavel

Reputation: 1345

instead of

if ($retcode == "200")
    {
     header("url=$location");
    }

try using

if ($retcode == "200")
    {
     echo '<META HTTP-EQUIV="refresh" CONTENT="0;URL='.$location.'">';
    }  

it will do a client side redirecting. I suppose this will help you!

Upvotes: 1

arkascha
arkascha

Reputation: 42984

I doubt there is a clean and pure html solution for this.

You should use client side scripting for this: you embed a small javascript function that polls the server either on a regular base or (preferred) using a long polling strategy to find out if the html page already exists. On a positive result it redirects the browser.

Upvotes: 0

Related Questions