检查字符串和用户代理
我正在尝试设置一个 PHP 片段来检查是否满足 2 个条件,如果满足,它会回显一些文本。条件是:
- 查询字符串等于某个值。
- 那个浏览器是Firefox。
它正在正确检查查询字符串,但是它似乎不适用于浏览器(用户代理)。请参阅下文:
<?php
function get_user_browser()
{
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$ub = '';
if(preg_match('/Firefox/i',$u_agent))
{
$ub = "firefox";
}
else
{
$ub = "other";
}
}
if (isset($_GET['print']) && $_GET['print'] != "" && $ub = 'firefox')
{
$pg = $_GET['print'];
if (!file_exists('1'))
{
echo '<b>It worked!</b>';
}
}
else
{
echo '';
}
?>
任何帮助将不胜感激。
I am trying to setup a PHP snippet that checks if 2 conditions are met and if they are, it echoes some text. The conditions are:
- That the query string equals a certain value.
- That the browser is Firefox.
It's checking the query string properly but, it doesnt seem to be working for the browser (user agent). See below:
<?php
function get_user_browser()
{
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$ub = '';
if(preg_match('/Firefox/i',$u_agent))
{
$ub = "firefox";
}
else
{
$ub = "other";
}
}
if (isset($_GET['print']) && $_GET['print'] != "" && $ub = 'firefox')
{
$pg = $_GET['print'];
if (!file_exists('1'))
{
echo '<b>It worked!</b>';
}
}
else
{
echo '';
}
?>
Any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这就是我检查这些东西的方法:
并添加到您的代码中:
This is what i do to check out that stuff:
And added into your code:
这是我使用的;
您还可以看看;
https://github.com/donatj/PhpUserAgent
Here is what i use;
you can also have a look at;
https://github.com/donatj/PhpUserAgent
我看不到您的代码调用该函数,因此 $ub 在您的条件下不起作用。
I can't see your code calling the function, and thus $ub doesn't work in your condition.