1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

PHP header:location and referrer

Discussion in 'PHP' started by bobby9101, Sep 5, 2007.

  1. #1
    Hi, on Page 1 I am using
    header("location:page2.php")
    PHP:
    and on Page 2 I want to use
    $_SERVER['HTTP_REFERER']
    PHP:
    to display the page that referred it. However this does not work, I read some on Google that you can use
    header("referer:page1.php")
    PHP:
    to pass the referrer, but it isn't working for me. Any ideas?
     
    bobby9101, Sep 5, 2007 IP
  2. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try with an uppercase 'r' and a space between the ':' and the uri

    
    header("Referer: page1.php");
    
    PHP:
     
    sea otter, Sep 5, 2007 IP
  3. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #3
    still didn't work :confused:
     
    bobby9101, Sep 5, 2007 IP
  4. rederick

    rederick Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I've never been able to rely on the HTTP_REFERER

    Instead I use a session variable on each page that stores the REQUEST_URI
    call it $_SESSION['url_back'] or something. Then that session variable should always contain the last page the user was on ... Might work for what you are doing?
     
    rederick, Sep 5, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    Because you can't. The referer is sent by the browser, and not all browsers send it by default. Plus it can be faked/modified by the user. It's nothing to rely on.
     
    nico_swd, Sep 6, 2007 IP
  6. rederick

    rederick Peon

    Messages:
    128
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Exactly. Some Firewalls and anti-virus software will also strip out the referer. My method by setting a session var on each page to the current page seems to be a valid way to track which page the user last visited though.
     
    rederick, Sep 6, 2007 IP
  7. James.Blant

    James.Blant Active Member

    Messages:
    250
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #7
    hehe :D
    test this .
    i was use this code for change referers of un-natural traffic to natural traffic from search engines :D and it working fine for me .
    
    <?php
    
    $host = 'www.yourtargeturl.com';
    $service_uri = '/detect_referal.php';
    $vars ='additional_option1=yes&additional_option2=un';
    
    $header = "Host: $host\r\n";
    $header .= "User-Agent: PHP Script\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Referer: http://www.google.com/search?hl=en&q=jigh&btnG=Google+Search \r\n";
    $header .= "Content-Length: ".strlen($vars)."\r\n";
    $header .= "Connection: close\r\n\r\n";
    
    $fp = fsockopen("".$host,80, $errno, $errstr);
    
    if (!$fp) {
      echo "$errstr ($errno)<br/>\n";
      echo $fp;
    } else {
    fputs($fp, "POST $service_uri  HTTP/1.1\r\n");
    fputs($fp, $header.$vars);
    fwrite($fp, $out);
    
    while (!feof($fp)) {
    echo fgets($fp, 128);
    }
    fclose($fp);
    }
    ?> 
    PHP:
     
    James.Blant, Sep 6, 2007 IP
  8. bobby9101

    bobby9101 Peon

    Messages:
    3,292
    Likes Received:
    134
    Best Answers:
    0
    Trophy Points:
    0
    #8
    I'm just using sessions
     
    bobby9101, Sep 6, 2007 IP
  9. suraja

    suraja Peon

    Messages:
    537
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I'd like to test it, but where's detect_referal.php ?

     
    suraja, Feb 8, 2008 IP
  10. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #10
    
    <?php
    
    echo $_SERVER['HTTP_USER_AGENT'];
    
    ?>
    
    PHP:
    Here.
     
    nico_swd, Feb 8, 2008 IP
  11. James.Blant

    James.Blant Active Member

    Messages:
    250
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #11
    you should create detect_referal.php on your own server ( with PHP ) and echo $_SERVER['HTTP_REFERER'] .
     
    James.Blant, Feb 9, 2008 IP
  12. pile

    pile Member

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #12
    can u give the complete code, i have try it but returns error :(
     
    pile, Feb 26, 2008 IP
  13. James.Blant

    James.Blant Active Member

    Messages:
    250
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #13
    that's complete !!!
     
    James.Blant, Feb 27, 2008 IP
  14. jpinheiro

    jpinheiro Peon

    Messages:
    1,211
    Likes Received:
    15
    Best Answers:
    1
    Trophy Points:
    0
    #14
    @pile

    Detect_Referal.php
    
    
    
    <?php
    
    echo $_SERVER['HTTP_REFERER']
    
    ?>
    
    
    PHP:
     
    jpinheiro, Aug 9, 2008 IP
  15. James.Blant

    James.Blant Active Member

    Messages:
    250
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #15
    someone use my codes and got extra header information on output like this :
    i work on my codes to hide or pass this codes , post your solution here if you can resolve it sooner .
     
    James.Blant, Aug 9, 2008 IP
  16. Revolution333

    Revolution333 Peon

    Messages:
    227
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #16
    Try and take away the "echo" because I don't know why it would show any information.

    EDIT:

    It actually might be:
    echo fgets($fp, 128);
    Code (markup):
     
    Revolution333, Aug 9, 2008 IP
  17. James.Blant

    James.Blant Active Member

    Messages:
    250
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #17
    while (!feof($fp)) {
    echo fgets($fp, 128);
    }
    PHP:
    it's same !
     
    James.Blant, Aug 9, 2008 IP
  18. lwbbs

    lwbbs Well-Known Member

    Messages:
    331
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    108
    #18
    This way can't transfer the URL in web browser to the target URL.

     
    lwbbs, Nov 3, 2008 IP