我有一个网址短脚本。有一个'forward.php‘文件,如果它被缩短了,它被用来重定向查询。但在这个文件中,我希望在将其重定向到原始url之前显示一些文本或广告5-10秒。
我还尝试了sleep()、flush()和all,但没有任何帮助。
谢谢。
代码:
<?php
ob_start();
require("lib/config.php");
require("lib/common.php");
if( isset($_SERVER['QUERY_STRING']) ){
$i = $_SERVER['QUERY_STRING'];
}else{
$i = $_SERVER['REQUEST_URI'];
$i = str_replace("/","",$i);
}
$suffix = $i{0};
$result = mysql_query("SELECT id,url FROM urls WHERE short_url = '$i'",DBH) or die(mysql_error());
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
$id = $row['id'];
$url = $row['url'];
mysql_query("UPDATE urls SET hits=hits+1 WHERE id = '{$id}'",DBH);
if ($_SESSION['config']['bar'] == true)
{
$meela_urllow = stripslashes(str_replace(",", "%2C", $url));
$meela_urllow = strtolower($meela_urllow);
if ((strpos($meela_urllow, "youtube")))
{
header('HTTP/1.1 301 Moved Permanently');
header("Location: ".stripslashes(str_replace(",", "%2C", $url)));
}
if ((strpos($meela_urllow, "facebook")))
{
header('HTTP/1.1 301 Moved Permanently');
header("Location: ".stripslashes(str_replace(",", "%2C", $url)));
}
if ((strpos($meela_urllow, "google")))
{
header('HTTP/1.1 301 Moved Permanently');
header("Location: ".stripslashes(str_replace(",", "%2C", $url)));
}
} else {
header('HTTP/1.1 301 Moved Permanently');
header("Location: ".stripslashes(str_replace(",", "%2C", $url)));
}
exit;
}
header('HTTP/1.1 301 Moved Permanently');
header("Location: http://".$_SESSION['config']['domain']);
exit;
?>发布于 2013-08-25 18:30:47
如果想在重定向前显示文本,需要使用带刷新值的header()函数:
header('Refresh: 5; url=some_url.php'); // tell browser to wait 5 sec then redirect休眠一个php脚本和暂停它是一样的。脚本将会挂起,什么也不做,使用输出缓冲区也无济于事,因为必须在发送任何Location主体之前发送HTTP头,所以唯一的选项是使用头刷新。
这与使用header()函数相同,但不需要php代码:https://stackoverflow.com/a/737003/555097
https://stackoverflow.com/questions/18428008
复制相似问题