gpt4 book ai didi

php - 是否可以不设置 $_SERVER ['HTTP_USER_AGENT' ]?

转载 作者:IT王子 更新时间:2023-10-28 23:45:29 25 4
gpt4 key购买 nike

我刚刚查看了一个网站的error_log,其中一个已被记录了几次的错误是:

[21-Jun-2011 12:24:03] PHP 注意:未定义索引:/home/ukevents/public_html/lib/toro.php 第 130 行中的 HTTP_USER_AGENT

toro.php 相关的行是:

private function ipad_request() {
return strstr($_SERVER['HTTP_USER_AGENT'], 'iPad');
}

是否有可能 $_SERVER['HTTP_USER_AGENT'] 不被 HTTP 请求设置?

最佳答案

是的,这是可能的,这是客户端发送(或未发送)的 HTTP header ,您不应该依赖它。来自 php 手册:

Contents of the User-Agent: header from the current request, if there is one

所以正确的代码应该是:

private function ipad_request() {
return isset($_SERVER['HTTP_USER_AGENT']) && strstr($_SERVER['HTTP_USER_AGENT'], 'iPad');
}

关于php - 是否可以不设置 $_SERVER ['HTTP_USER_AGENT' ]?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6465397/

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