Welcome to WebmasterWorld Guest from 54.205.96.97

Forum Moderators: coopster & jatar k

Get the actual browser url using php

The one in the address bar - not $_SERVER['REQUEST_URI']

   
3:45 am on Feb 20, 2006 (gmt 0)

10+ Year Member



This follows on from a post made by jake66 [webmasterworld.com...] who wanted the address bar url.

I'd like to get the actual url typed in the browser - not the $_SERVER['REQUEST_URI'].

One of my pages is being picked up in google as a duplicate when it is in fact the original. The infringing site is showing 'You searched for these terms'
and then shows my page below (highlighing the search terms), requested live from my server.
The url indexed by google shows as www.theirsite.com:2007/sthl?st=Weight+Loss+Help&url=http%3A%2F%2Fwww.mysite.com
$_SERVER['REQUEST_URI'] returns 'www.mysite.com' and not 'www.theirsite.com'

I want get the original url from the browser so I can replace my original page with a 'View this page here' message if the originating url is not from mysite.com
Is it possible using PHP only or am I right in thinking it is only possible using javascript?

3:54 am on Feb 20, 2006 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



You probably want to look at $_SERVER['HTTP_REFERER']
4:43 am on Feb 20, 2006 (gmt 0)

10+ Year Member



The problem is that $_SERVER['HTTP_REFERER'] is not being set by the site. Any other ideas?
5:20 am on Feb 20, 2006 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Do you have any idea how they are redirecting to your site?
6:27 am on Feb 20, 2006 (gmt 0)

10+ Year Member



It is not actually a redirect. I think what is happening is that the site is requesting the current page from my site. It then parses the page adding their table with 'The following search terms have been highlighted: search terms' and adding style="background-color: tags throughout my pages html. It then serves up this page on their site. I want to catch it when they first request the page so they do not get the html to alter.
Looking at my server logs it seems that the initial request for index.php does not have a referrer but the requests for the .css and images do.
8:46 am on Feb 20, 2006 (gmt 0)

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member



How about simply blocking their IP?
1:07 am on Feb 21, 2006 (gmt 0)

10+ Year Member



I initially looked at doing this as the best way to do it but blocking the IP address of their site did not seem to work. After you posted again I took another look at the server logs to see if I had gone wrong somewhere. Turns out the request for the page was not coming from the same IP address of the site but from another one in the same range. Once this was blocked - bingo.
Thanks for your help DrDoc.
5:48 pm on Mar 10, 2006 (gmt 0)

5+ Year Member



Here's your solution...

<?
$url = $_SERVER['SERVER_NAME'];
$page = $_SERVER['PHP_SELF'];
echo "http://".$url.$page;
?>

displays...

[the_url.com...]

9:39 pm on Mar 10, 2006 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Welcome to WebmasterWorld, arubahost.

As a side not, REQUEST_URI and PHP_SELF are going to look a lot the same ... you will notice a difference though when you use mod_rewrite or Content Negotiation.

11:38 pm on Mar 10, 2006 (gmt 0)

10+ Year Member



arubahost,
I just tried your solution to see but it did not work.
It returned www.mysite.com/index.php
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month