我想$_SERVER['HTTP_REFERER']在我的网站上使用,但得到以下信息:Notice: Undefined index: HTTP_REFERER 我试过打印$_SERVER。输出以下内容:Array( [HTTP_HOST] => 192.168.1.10 [HTTP_USER_AGENT] => Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:15.0) Gecko/20100101 Firefox/15.0 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5 [HTTP_ACCEPT_ENCODING] => gzip, deflate [HTTP_CONNECTION] => keep-alive [PATH] => /sbin:/usr/sbin:/bin:/usr/bin [SERVER_SIGNATURE] => Apache/2.2.3 (CentOS) Server at 192.168.1.10 Port 80 [SERVER_SOFTWARE] => Apache/2.2.3 (CentOS) [SERVER_NAME] => 192.168.1.10 [SERVER_ADDR] => 192.168.1.10 [SERVER_PORT] => 80 [REMOTE_ADDR] => 192.168.1.77 [DOCUMENT_ROOT] => /var/www/html [SERVER_ADMIN] => root@localhost [SCRIPT_FILENAME] => /var/www/html/sandeep/test/hash.php [REMOTE_PORT] => 53851 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => GET [QUERY_STRING] => [REQUEST_URI] => /sandeep/test/hash.php [SCRIPT_NAME] => /sandeep/test/hash.php [PHP_SELF] => /sandeep/test/hash.php [REQUEST_TIME] => 1347365919)谁能帮助我找到HTTP_REFERER或建议替代方案HTTP_REFERER?
3 回答
潇湘沐
TA贡献1816条经验 获得超6个赞
当网络浏览器从一个网站移动到另一个网站并在网站页面之间移动时,它可以选择传递其来源的URL。这称为HTTP_REFERER,因此,如果您不从一个页面重定向到另一页面,则可能会丢失
如果已设置HTTP_REFERER,则将显示它。如果不是,那么您将看不到任何东西。如果未设置,并且您设置了要显示通知的错误报告,则会看到类似以下的错误:
Notice: Undefined index: HTTP_REFERER in /path/to/filename.php
为了防止在打开通知时发生此错误(我总是在打开通知的情况下进行开发),您可以这样做:
if(isset($_SERVER['HTTP_REFERER'])) {
echo $_SERVER['HTTP_REFERER'];
}
要么
echo isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
使用$ _SERVER ['HTTP_REFERER']超全局变量将HTTP_REFERER变量用于日志记录等用途可能会很有用。但是,重要的是要知道它并不总是设置的,因此如果您在发出通知的情况下进行编程,则需要在代码中允许这样做
- 3 回答
- 0 关注
- 6183 浏览
添加回答
举报
0/150
提交
取消