我正在嘗試將一些第三方跟蹤代碼集成到我的網站之一,但它是拋出一些錯誤,並且他們的支持沒有多大用處,所以我想要嘗試自己修復他們的代碼。最讓我有固定的,但是這個功能是給我的問題:X轉發 - 爲PHP中導致未定義的索引
private function getXForwardedFor()
{
$s =& $this;
$xff_ips = array();
$headers = $s->getHTTPHeaders();
if ($headers['X-Forwarded-For']) {
$xff_ips[] = $headers['X-Forwarded-For'];
}
if ($_SERVER['REMOTE_ADDR']) {
$xff_ips[] = $_SERVER['REMOTE_ADDR'];
}
return implode(', ', $xff_ips); // will return blank if not on a web server
}
在我的開發環境在那裏我顯示所有的錯誤我得到:1129
Notice: Undefined index: X-Forwarded-For in /sites/webs/includes/OmnitureMeasurement.class.php on line 1129
線路是:
if ($headers['X-Forwarded-For']) {
如果我打印出$標題,我會得到:
Array
(
[Host] => www.domain.com
[User-Agent] => Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3
[Accept] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[Accept-Language] => en-gb,en;q=0.5
[Accept-Encoding] => gzip,deflate
[Accept-Charset] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
[Keep-Alive] => 115
[Connection] => keep-alive
[Referer] => http://www10.toptable.com/
[Cookie] => PHPSESSID=nh9jd1ianmr4jon2rr7lo0g553; __utmb=134653559.30.10.1275901644; __utmc=134653559
[Cache-Control] => max-age=0
)
我看不到X-Forwarded-For在那裏,我認爲是造成問題。有什麼我應該添加到功能考慮到這一點?
我在Fedora
和再見錯誤消息。非常感謝。 (只要它讓我接受!) – 2010-06-07 13:22:51