homepage Welcome to WebmasterWorld Guest from 54.196.63.93
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Get the actual browser url using php
The one in the address bar - not $_SERVER['REQUEST_URI']
Gibisan

10+ Year Member



 
Msg#: 11818 posted 3:45 am on Feb 20, 2006 (gmt 0)

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?

 

DrDoc

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



 
Msg#: 11818 posted 3:54 am on Feb 20, 2006 (gmt 0)

You probably want to look at $_SERVER['HTTP_REFERER']

Gibisan

10+ Year Member



 
Msg#: 11818 posted 4:43 am on Feb 20, 2006 (gmt 0)

The problem is that $_SERVER['HTTP_REFERER'] is not being set by the site. Any other ideas?

DrDoc

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



 
Msg#: 11818 posted 5:20 am on Feb 20, 2006 (gmt 0)

Do you have any idea how they are redirecting to your site?

Gibisan

10+ Year Member



 
Msg#: 11818 posted 6:27 am on Feb 20, 2006 (gmt 0)

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.

DrDoc

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



 
Msg#: 11818 posted 8:46 am on Feb 20, 2006 (gmt 0)

How about simply blocking their IP?

Gibisan

10+ Year Member



 
Msg#: 11818 posted 1:07 am on Feb 21, 2006 (gmt 0)

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.

arubahost

5+ Year Member



 
Msg#: 11818 posted 5:48 pm on Mar 10, 2006 (gmt 0)

Here's your solution...

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

displays...

[the_url.com...]

coopster

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



 
Msg#: 11818 posted 9:39 pm on Mar 10, 2006 (gmt 0)

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.

Gibisan

10+ Year Member



 
Msg#: 11818 posted 11:38 pm on Mar 10, 2006 (gmt 0)

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

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved