gpt4 book ai didi

php - 如何访问 apache 中的唯一 ID?

转载 作者:行者123 更新时间:2023-12-05 07:59:06 28 4
gpt4 key购买 nike

我如何访问 apache 为每个请求跟踪的 unique_id?我想在它调用的任何 php 脚本中跟踪它,并为每个请求记录它。

我从 http.conf 文件中删除了以下行的注释:

LoadModule unique_id_module libexec/apache2/mod_unique_id.so

我正尝试在这个简单的 php 脚本中引用 ID:

<?php

print("Hello world\n");
print($_SERVER['UNIQUE_ID']);
?>

然而这个脚本只返回Hello World

这可能吗?如果有任何不同,我正在运行 macos。

$_SERVER 的 var_dump 如下:

array(29) { ["HTTP_HOST"]=> string(9) "localhost" 
["HTTP_CONNECTION"]=> string(10) "keep-alive"
["HTTP_CACHE_CONTROL"]=> string(9) "max-age=0"
["HTTP_ACCEPT"]=> string(74) "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" ["HTTP_USER_AGENT"]=> string(120) "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.117 Safari/537.36" ["HTTP_ACCEPT_ENCODING"]=> string(17) "gzip,deflate,sdch"
["HTTP_ACCEPT_LANGUAGE"]=> string(14) "en-US,en;q=0.8"
["HTTP_COOKIE"]=> string(11) "undefined=0"
["PATH"]=> string(186) "/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/opt/X11/bin:/opt/local/lib/postgresql84/bin:/Applications/XAMPP/xamppfiles/bin"
["SERVER_SIGNATURE"]=> string(0) ""
["SERVER_SOFTWARE"]=> string(67) "Apache/2.2.24 (Unix) DAV/2 PHP/5.3.26 mod_ssl/2.2.24 OpenSSL/0.9.8y"
["SERVER_NAME"]=> string(9) "localhost"
["SERVER_ADDR"]=> string(3) "::1"
["SERVER_PORT"]=> string(2) "80"
["REMOTE_ADDR"]=> string(3) "::1"
["DOCUMENT_ROOT"]=> string(28) "/Library/WebServer/Documents"
["SERVER_ADMIN"]=> string(15) "you@example.com"
["SCRIPT_FILENAME"]=> string(35) "/Library/WebServer/Documents/id.php"
["REMOTE_PORT"]=> string(5) "49669"
["GATEWAY_INTERFACE"]=> string(7) "CGI/1.1"
["SERVER_PROTOCOL"]=> string(8) "HTTP/1.1"
["REQUEST_METHOD"]=> string(3) "GET"
["QUERY_STRING"]=> string(0) ""
["REQUEST_URI"]=> string(7) "/id.php"
["SCRIPT_NAME"]=> string(7) "/id.php"
["PHP_SELF"]=> string(7) "/id.php"
["REQUEST_TIME"]=> int(1397681759)
["argv"]=> array(0) { }
["argc"]=> int(0) }

我在同一区域遇到的另一个问题可能指向手头的问题:https://apple.stackexchange.com/questions/127801/where-are-the-apache-config-files-stored?noredirect=1#comment149749_127801

最佳答案

如赏金评论中所述,在 OS X 上存在一些与配置文件有关的问题。例如,在 OS X 10.7 上,我在 httpd.conf 中成功启用了 mod_unique_id,如果我通过 Preference Pane - Web Sharing 重新启动,一切都按预期工作,但如果我通过 apachectl 命令重新启动,则会出现一些奇怪的问题。

在 OS X 10.9 中,首选项 Pane 中没有 Web 共享,所以我的建议是坚持使用 PHP 的唯一 ID 生成器,例如这些功能可能会有所帮助: http://www.php.net/manual/en/function.uniqid.phphttp://www.php.net/manual/en/function.openssl-random-pseudo-bytes.php

关于php - 如何访问 apache 中的唯一 ID?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22929742/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com