在PHP中删除查询字符串(有时基于引荐来源网址) [英] Removing query string in PHP (sometimes based on referrer)

查看:54
本文介绍了在PHP中删除查询字符串(有时基于引荐来源网址)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,在Facebook上,首页链接上有一个查询字符串,如下所示:facebook.com/?ref=home单击链接并导航到首页时,查询会自动删除.但是,如果我要手动键入该链接,则会删除查询.关于他们如何做到这一点的任何想法?

Hi on Facebook the home link has a query string on it like this: facebook.com/?ref=home when you click the link and navigate to the home page the query is automatically removed. However if I was to manually type in that link the query is NOT removed. Any idea on how they did this?

推荐答案

PHP中最简单的方法:

Easiest way in PHP:

$url = preg_replace('/\?.*/', '', $url);

Facebook所做的可能就是这种方式的JavaScript:

What Facebook does is probably a JavaScript thing, in that fashion:

if (location.href.match(/\?.*/) && document.referrer) {
   location.href = location.href.replace(/\?.*/, '');
}

这篇关于在PHP中删除查询字符串(有时基于引荐来源网址)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆