php script to show where a visitor comes from

Discussion in 'PHP' started by zenite, Apr 12, 2008.

  1. #1
    I am looking for a php script that shows where a visitor comes from. lets say Visitor A comes to my webpage via a link on domain.com

    The script will be able to show on the webpage "domain.com" using the echo function.

    I tried this:
    $_SERVER['HTTP_REFERER'];

    but all it shows is the URL of my own webpage instead of the referring webpage.
     
    zenite, Apr 12, 2008 IP
  2. jjacquay712

    jjacquay712 Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    do you have a link that you are coming from or are you just typing in domain.com? that might be the problem...lol
     
    jjacquay712, Apr 12, 2008 IP
  3. zenite

    zenite Peon

    Messages:
    240
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    duh. I DO have a link I am coming from. I placed a link on another of my website to test it. heres the full php code:

    <?php
    $referer = $_SERVER["HTTP_REFERER"];
    $ipaddress = $_SERVER['REMOTE_ADDR'];	//  Requestor IP addr
    $request_uri = ltrim($_SERVER['REQUEST_URI'],'/');
    
    if ($_SERVER["HTTP_REFERER"]) {
    $parsed = @parse_url(strtolower($referer));
    	if ($parsed[host] && !eregi(strtolower("domain.com"),$parsed[host])) {
    	echo '<a href="http://';
    	echo str_replace("statistics.","www.",str_replace("stats.","www.",$parsed[host]));
    	echo '/">';
    	echo ucfirst(str_replace("statistics.","",str_replace("stats.","",str_replace("www.","",$parsed[host]))))."</a>";
    	}
    }
    ?>
    PHP:
     
    zenite, Apr 12, 2008 IP
  4. only1idea

    only1idea Peon

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you can use javascript if you want, just check the
    document.referrer
    Code (markup):
    :)
     
    only1idea, Apr 13, 2008 IP
  5. zenite

    zenite Peon

    Messages:
    240
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    yeah, thats the good alternative, but I do not want to use it unless it is the only choice. I wanted a solution that can output to HTML (php) so that ppl cannot view the code I used. Javascript can be seen in View Source which is not what I want.
     
    zenite, Apr 14, 2008 IP