Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing query string in PHP (sometimes based on referrer)

Tags:

php

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?

like image 909
Cameron Avatar asked Nov 24 '10 19:11

Cameron


1 Answers

Easiest way in PHP:

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

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

if (location.href.match(/\?.*/) && document.referrer) {    location.href = location.href.replace(/\?.*/, ''); } 
like image 112
netcoder Avatar answered Sep 28 '22 05:09

netcoder