如何将 strstr 与 $_SERVER['HTTP_REFERER'] 一起使用

发布于 2024-08-22 11:52:28 字数 942 浏览 11 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神妖 2024-08-29 11:52:28

更改 &到&&。这是大多数编程语言中逻辑“与”的常用运算符。

在 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.

习惯成性 2024-08-29 11:52:28

我认为您使用了错误的 AND 运算符,您应该使用 && 而不仅仅是 &。单个 & 符号用于按位运算。

尝试:

if (isset($result['q']) && strstr($_SERVER['HTTP_REFERER'],'google'))

I think you're using the wrong AND operator, you should use && not just &. the single ampersand is for bitwise operations.

Try:

if (isset($result['q']) && strstr($_SERVER['HTTP_REFERER'],'google'))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文