I’m using some code like this to grab the URL from an inbound link:
$inbound_url = $_SERVER['HTTP_REFERER'];
//then do some stuff writing the url to a database table, but....
//ONLY IF the url doesn't already exist in the table
Let’s say the link comes in from the same website, same webpage, but different only in the www. So I get this:
1) http://www.mysite.com/page.html
2) http://mysite.com/page.html
This shows up twice in my table since one has the www and one doesn’t.
Is there a way to parse the results of $_SERVER[‘HTTP_REFERER’]; to either:
1) add www. where it’s missing, OR
2) strip everything of …http://…www. or ..http://
Thanks in advance as always.
Sure you can. Some simple string manipulation and replacement should be all you need to remove the
wwwfrom any URL –As defined in the documentation –
Notice that I’m including the
http://in the search so that any other occurrence of the stringwwwURL will remain untouched.