如何将 strstr 与 $_SERVER['HTTP_REFERER'] 一起使用
我使用 php 来制作它,以便我的网站的传入流量将根据搜索引擎附加信息。我正在设置 $_SESSION['kw'],如果尚未设置,则告诉我它是 seo 并附加搜索词:
if (isset($result['q']))
$_SESSION['kw'] = 'seo-'.str_replace('\\"',"X",$result['q']);
elseif (isset($result['p']))
$_SESSION['kw'] = 'seo-'.$result['p'];
else {some other stuff}
q 是 google、msn 和 Ask 用于查询的内容,p 是 yahoo。这涵盖了大部分传入流量。好的,现在我想稍微改变一下,这样如果引用页面是 yahoo,它会附加一个 Y,如果它是 google 则附加一个 G,msn M 等。
我尝试过:
if (isset($result['q'])& strstr($_SERVER['HTTP_REFERER'],'google'))
$_SESSION['kw'] = 'seo-G-'.str_replace('\\"',"X",$result['q']);
elseif (isset($result['q'])& !strstr($_SERVER['HTTP_REFERER'],'google'))
$_SESSION['kw'] = 'seo-M-'.str_replace('\\"',"X",$result['q']);
elseif (isset($result['p']))
$_SESSION['kw'] = 'seo-Y-'.$result['p'];
else {some other stuff}
但我无法使第一个 IF 为真。如果我来自ask.com,我会得到“附加了seo-M”,但即使来自谷歌,我也无法将其附加。我只是格式错误吗?
I'm using php to make it so that incoming traffic to my website will append information depending on the search engine. I'm setting $_SESSION['kw'], if it's not already set, to tel me that it's seo and to append the search terms:
if (isset($result['q']))
$_SESSION['kw'] = 'seo-'.str_replace('\\"',"X",$result['q']);
elseif (isset($result['p']))
$_SESSION['kw'] = 'seo-'.$result['p'];
else {some other stuff}
q is what google, msn and ask use for their queries, p is for yahoo. That covers most of the incoming traffic. OK so now I want to change it a bit so that if the referring page is yahoo, it appends a Y, if it's google a G, msn M etc.
I tried:
if (isset($result['q'])& strstr($_SERVER['HTTP_REFERER'],'google'))
$_SESSION['kw'] = 'seo-G-'.str_replace('\\"',"X",$result['q']);
elseif (isset($result['q'])& !strstr($_SERVER['HTTP_REFERER'],'google'))
$_SESSION['kw'] = 'seo-M-'.str_replace('\\"',"X",$result['q']);
elseif (isset($result['p']))
$_SESSION['kw'] = 'seo-Y-'.$result['p'];
else {some other stuff}
But I can't make the first IF true. If I come from ask.com, I get "seo-M appended", but I can't even when coming from google, get it to append. Am I just formatting it wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更改 &到&&。这是大多数编程语言中逻辑“与”的常用运算符。
在 PHP 中,您有 &&或 AND 用于逻辑布尔运算。
&通常用于位操作,这里是错误的。
Change the & to &&. This is the usual operator for most programming languages for a logical "and"
In PHP you have && or AND for logical bool operations.
& is usually used for bit-operations, which is wrong here.
我认为您使用了错误的 AND 运算符,您应该使用
&&
而不仅仅是&
。单个 & 符号用于按位运算。尝试:
I think you're using the wrong AND operator, you should use
&&
not just&
. the single ampersand is for bitwise operations.Try: