Set referer header in php?

Discussion in 'PHP' started by Eget25, Aug 28, 2009.

  1. #1
    Hi everybody,
    I would appreciated your help with my problem.
    I need to show one page in my site when user come in but the page is protected by referer check so it redirect itself to page where it should be redirected from.

    Basically I need to do redirect on my site to
    www.notmypage.com/secondpage.html
    Code (markup):
    with referer header
    www.notmypage.com/firstpage.html 
    Code (markup):
    I tried this:
    header('Referer: www.notmypage.com/firstpage.html');
    header('Location: www.notmypage.com/secondpage.html');
    Code (markup):
    but it doesn't work

    So I tried this:
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_REFERER, "www.notmypage.com/firstpage.html");
    curl_setopt($ch, CURLOPT_URL, "www.notmypage.com/secondpage.html");
    $content =curl_exec ($ch);
    echo $content;
    Code (markup):
    And it did work but with one big problem, it sending server's IP instead of visitors IP. And that's where I get stuck.

    I find a lot of same questions on few forums and most of users were answering that it can't be done but I believe that some one can pull it off.

    Please help.
     
    Eget25, Aug 28, 2009 IP
  2. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #2
    In your script you checked for the right referrer and then echoed content from secondpage.html, but you fetched that content via CURL (which is server sided), so users cant have any idea where was that content fetched from. Why not trying to redirect your users via JavaScript?

    Instead of
    
    $ch = curl_init();
    curl_setopt($ch,CURLOPT_REFERER, "www.notmypage.com/firstpage.html");
    curl_setopt($ch, CURLOPT_URL, "www.notmypage.com/secondpage.html");
    $content =curl_exec ($ch);
    echo $content;
    
    PHP:
    add this HTML code
    
    <script type="text/javascript">
    <!--
    window.location = "www.notmypage.com/secondpage.html";
    //-->
    </script>
    
    PHP:
    P.S. Also remember, headers are sent by your client's browser, so you cant manipulate them in ANY way with PHP.
     
    Gray Fox, Aug 28, 2009 IP
  3. osmasters

    osmasters Well-Known Member

    Messages:
    453
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    100
    #3
    osmasters, Aug 28, 2009 IP
  4. Eget25

    Eget25 Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I echoed it because I needed to see result if I get right page.
    Ok I can do it with javascript but is there also script which changes referer page? I won't get secondpage.html if I don't go trough firstpage.html.
     
    Eget25, Aug 29, 2009 IP