2013-02-22 59 views
-3

我想使用刷新作爲重定向功能,因爲標題不起作用的原因。下面是一段我的代碼,當我運行它刷新循環:刷新網站使用未知的網址

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

$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.'">'; 
} 
+0

如果您想更新+1的整數,然後隨之改變您的查詢:'那非那韋SET NFV = '那非那韋' + 1' – 2013-02-22 01:15:31

+0

什麼substr for?原始的REQUEST_URI是什麼樣的? – shapeshifter 2013-02-22 01:18:10

+0

我想擁有:index.php?site =頁面insted//folder/index.php?site=page所以這就是爲什麼我使用substr – qerigan 2013-02-22 01:24:19

回答

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

我說過,頭不工作 – qerigan 2013-02-22 01:17:02

+0

@qerigan在哪裏? ***什麼***不工作? – Kermit 2013-02-22 01:17:13

+0

標題可能已經發送,緩衝您的輸出 – shapeshifter 2013-02-22 01:19:15

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; 
+0

我之前說過,標題不工作,閱讀有問題嗎? – qerigan 2013-02-22 01:18:29

+0

哈哈哈我認爲你是一個有問題的人閱讀 – shapeshifter 2013-02-22 01:25:53

+0

爲什麼你沒有工作頭我複製粘貼代碼從谷歌 – shapeshifter 2013-02-22 01:26:13