简体   繁体   English

创建页面后,重定向到URL

[英]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. 创建网站后,我想向用户显示一个保留页面,该保留页面已被新网站的index.html页面替换。

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. 我对此略有深入,但是尝试将保留页代码放在代码的开头,然后在末尾插入以下代码以验证index.html文件。 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;
    }
?>

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! 我想这对您有帮助!

I doubt there is a clean and pure html solution for this. 我怀疑是否有一个干净的纯HTML解决方案。

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. 您应该为此使用客户端脚本编制:您嵌入了一个小的javascript函数,该函数以常规形式或(使用长轮询策略)(首选)轮询服务器以查明html页面是否已存在。 On a positive result it redirects the browser. 如果结果是肯定的,它将重定向浏览器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM