Php include中未定义的索引
我收到以下错误通知:未定义索引:include()中的HTTP\u USER\u AGENT但是我没有定义Php include中未定义的索引,php,Php,我收到以下错误通知:未定义索引:include()中的HTTP\u USER\u AGENT但是我没有定义HTTP\u USER\u AGENT function get_browser_name($user_agent) { if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera'; elseif (strpos($user_agent, 'Edge')) return 'Ed
HTTP\u USER\u AGENT
function get_browser_name($user_agent)
{
if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
elseif (strpos($user_agent, 'Edge')) return 'Edge';
elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
elseif (strpos($user_agent, 'Safari')) return 'Safari';
elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Explorer';
return 'Other';
}
错误在这一行:
<body class="<?php echo get_browser_name($_SERVER['HTTP_USER_AGENT']);?>" <?php print $attributes;?> <?php print $classes; ?>>
引用人
该代码在未用作包含时有效?标题可能未设置。但您正在传递$\u SERVER['HTTP\u USER\u AGENT']
如果您向我们显示完整的错误消息并根据您显示的代码识别错误消息上的行号,我们可以help@RiggsFolly这是一个完全错误,剩下的页面只是文件位置和行号。行号精确地指向主体类线条。因此,您向我们展示的代码的哪一行是错误消息中提到的那一行请回答好的答案将始终解释所做的事情以及为什么这样做,不仅是为了OP,而且是为了未来的访问者,以便他们能够找到这个问题并阅读您的答案。如果它解决了这个问题,甚至可以投票表决。这是一个只有链接的答案
function get_browser_name($user_agent)
{
if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera';
elseif (strpos($user_agent, 'Edge')) return 'Edge';
elseif (strpos($user_agent, 'Chrome')) return 'Chrome';
elseif (strpos($user_agent, 'Safari')) return 'Safari';
elseif (strpos($user_agent, 'Firefox')) return 'Firefox';
elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'Internet Explorer';
return 'Other';
}
// Usage:
echo get_browser_name($_SERVER['HTTP_USER_AGENT']);