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.

Redirection kepping referer

Discussion in 'PHP' started by Bloraud, Sep 19, 2013.

  1. #1
    Hello

    I'm looking for a way to have a referer when I'm using a redirection.

    Let me explain.
    I have a page on domain1 which send the visitor to the domain2.
    I use a header redirection.

    But on domain2, I want to know if the visitor is coming by this redirection.
    Everytime I checked the referer, it's blank...

    Who can tell me how to redirect a visitor and identify it after ?

    Thanks a lot
     
    Solved! View solution.
    Bloraud, Sep 19, 2013 IP
  2. competent123

    competent123 Notable Member

    Messages:
    1,750
    Likes Received:
    71
    Best Answers:
    6
    Trophy Points:
    255
    #2
    redirect to domain2.com?something

    and in header put the relevant code

    it will show up in analytics
     
    competent123, Sep 19, 2013 IP
  3. Bloraud

    Bloraud Well-Known Member

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    100
    #3
    Hello

    My code in domain1 is :
    header("Status: 301 Moved Permanently", false, 301);
    header("Location: domain2");
    exit();

    I also try :
    header("Refresh: 0;url=domain2");
    exit();


    And the code on the second domain :
    $url =$_SERVER['HTTP_REFERER'];
    echo $url;
     
    Bloraud, Sep 19, 2013 IP
  4. #4
    What he is saying that you do something like:

    header("location: domain.com/?utm_source=domain1");
    Code (markup):
    Then on your domain 2 do:

    $referrer = isset($_GET['utm_source']) ?  $_GET['utm_source'] : 'no referrer';
    echo $referrer;  
    Code (markup):
     
    chifliiiii, Sep 19, 2013 IP
  5. Code Developer

    Code Developer Active Member

    Messages:
    48
    Likes Received:
    2
    Best Answers:
    2
    Trophy Points:
    58
    #5
    This snippet might get you in right direction:
    <?php
    $rdom = "http://domain.com/"; //Domain1
    $ref = $_SERVER['HTTP_REFERER']; //Get Referrer
    
    //Check if user coming from domain1
    if ($ref == $rdom) {
        echo "Correct"; //Correct Referrer
    }
    else {
        echo "Wrong"; //Wrong Referrer
    }
    ?>
    PHP:
     
    Code Developer, Sep 19, 2013 IP
  6. domainboom

    domainboom Active Member

    Messages:
    234
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    88
    #6
    You might find this helpful too :

    HTTP_REFERER is an environment variable sent by the browser. Some browsers give the user the option to remove it when making a http request.
     
    domainboom, Sep 19, 2013 IP
  7. Bloraud

    Bloraud Well-Known Member

    Messages:
    79
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    100
    #7
    Hello

    Thx to all of you.
    Unfortunatly, the redirection broke the referer so HTTP_REFERER is useless.

    But I used the technique with a special page and it's fine !

    So THANKS FOR YOUR HELP
     
    Bloraud, Sep 19, 2013 IP
  8. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #8
    Why not check if referer is external and then save it to a session?

    something like this
    
    if ($_SERVER['HTTP_REFERER'], 0, strlen($yourUrl)) != $yourUrl)
    {
         // ofcource session_start() must be started!
         $_SESSION['ref'] = $_SERVER['HTTP_REFERER'];
    }
    
    // do your header thing
    
    PHP:
     
    EricBruggema, Sep 25, 2013 IP