使用未知网址刷新网站

时间:2013-02-22 01:14:14

标签: php redirect refresh

我正在尝试使用refresh作为重定向功能,因为标头由于某种原因不起作用。这是我的代码片段,当我运行它时刷新循环:

----------不工作/ ---------------

$url = $_SERVER['REQUEST_URI'];
$url = substr($url, 10); //cuting url to "index.php?site=page"
echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$url.'">';

---------- WORKING / ---------------

$url = 'index.php?site=page';
echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$url.'">';

----------全能/ ---------------

elseif($action=="nfvi") {
        safe_query("UPDATE ".PREFIX."nfv SET nfv=nfv+1");
    $url = $_SERVER['REQUEST_URI'];
    $url = substr($url, 10);
    echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$url.'">';
}

2 个答案:

答案 0 :(得分:1)

为什么不使用HTTP标头?

<?php
$url = "http://www.google.com";

header("Location: index.php?site=" . urlencode($url)); /* Redirect browser */

/* Make sure that code below does not get executed when we redirect. */
exit;
?>

See the manual

答案 1 :(得分:1)

您可以使用CURL作为客户端启动:

它将平衡CURL_SET TIMEOUT:curl_setopt($ch, CURLOPT_TIMEOUT, 3);

$ ch = curl_init(); curl_setopt($ ch,CURLOPT_URL,$ ping_url); curl_setopt($ ch,CURLOPT_RETURNTRANSFER,true); curl_setopt($ ch,CURLOPT_POST,true); curl_setopt($ ch,CURLOPT_POSTFIELDS,trim($ request)); $ result = curl_exec($ ch); curl_close($ CH);

如果标题位置不起作用,您是否检查标题中的刷新页面?

 header("Refresh: 2;");

如果标头不起作用,请使用fsockets读取数据:

$host = 'www.example.com';
$service_uri = '/cgi-bin/processACT';
$vars ='code=22&act=TEST';

$header = "Host: $host\r\n";
$header .= "User-Agent: PHP Script\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: ".strlen($vars)."\r\n";
$header .= "Connection: close\r\n\r\n";

$fp = pfsockopen("ssl://".$host, 443, $errno, $errstr);
if (!$fp) {
   echo "$errstr ($errno)<br/>\n";
   echo $fp;
} else {
    fputs($fp, "POST $service_uri  HTTP/1.1\r\n");
    fputs($fp, $header.$vars);
    fwrite($fp, $out);
    while (!feof($fp)) {
    echo fgets($fp, 128);
    }
    fclose($fp);
} 

然后用sleep(3)秒制作一个循环,然后暂停。

为什么在PHP中使用元标记而不是标题?

header('Location: '.$url);

或完整标题重定向示例:

$host  = $_SERVER['HTTP_HOST'];
$uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
$extra = 'mypage.php';
header("Location: http://$host$uri/$extra");
exit;