编程语言
首页 > 编程语言> > php – 重定向后获取404’d文件的URL的最佳方法是什么?

php – 重定向后获取404’d文件的URL的最佳方法是什么?

作者:互联网

我正在使用需要将错误记录到数据库的PHP站点.因此,我已经设置了一个.htaccess文件,如下所示:

ErrorDocument 404 /404.php

404.php包含将日志插入数据库所需的所有日志记录功能.我遇到的问题是检索触发404的文件的URL.

以下是$_SERVER超全局数组的内容:

[HTTP_HOST] => {omitted}
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7
[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_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
[HTTP_KEEP_ALIVE] => 300
[HTTP_CONNECTION] => keep-alive
[PATH] => /usr/local/bin:/usr/bin:/bin
[SERVER_SIGNATURE] => 
[SERVER_SOFTWARE] => Apache/2.2.8 (Ubuntu)
[SERVER_NAME] => {omitted}
[SERVER_ADDR] => {omitted}
[SERVER_PORT] => 80
[REMOTE_ADDR] => {omitted}
[DOCUMENT_ROOT] => {omitted}
[SERVER_ADMIN] => [no address given]
[SCRIPT_FILENAME] => /404.php
[REMOTE_PORT] => 19274
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => 
[REQUEST_URI] => /404.php
[SCRIPT_NAME] => /404.php
[PHP_SELF] => /404.php
[REQUEST_TIME] => {omitted}

有什么建议?我读过的所有内容都推荐使用HTTP_REFERER项,但它似乎不存在.

提前致谢.

解决方法:

REQUEST_URI旨在包含请求的URL路径和查询.

标签:php,error-handling,http-status-code-404,error-logging
来源: https://codeday.me/bug/20190627/1300886.html