创建页面后,重定向到URL

时间:2012-12-09 15:47:36

标签: php redirect

我希望向用户显示一个保留页面,该页面在创建网站后将替换为新网站的index.html页面。

目前,我只能通过定时刷新来实现。

<?php
//DB connection and posting 

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

<?
ob_start(); 
?> 

..... HTML code of holding page

<? 
echo ob_get_clean();
?>

稍微偏离了我的深度,但尝试将保留页面代码放在代码的开头,然后在末尾插入以下代码以验证index.html文件。但没有运气。任何帮助非常感谢

<?
$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;
    }
?>

2 个答案:

答案 0 :(得分:1)

而不是

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

尝试使用

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

它将进行客户端重定向。我想这会对你有所帮助!

答案 1 :(得分:0)

我怀疑有一个干净,纯粹的HTML解决方案。

你应该使用客户端脚本:你嵌入了一个小的javascript函数,可以在常规基础上轮询服务器,或者(首选)使用长轮询策略来查明html页面是否已经存在。在肯定的结果上,它重定向浏览器。