PHP Redirect After Page loads

Discussion in 'PHP' started by hexxer, Mar 28, 2009.

  1. #1
    Ok, so basically i am using this existing code to redirect to a different page. I send traffic from adwords to www.mydomain.com/site1.php, which forwards to www.mydomain.com/page/. The referrer of the next page www.google.com shows www.mydomain.com/page/. If i were to do a header redirect, it would show www.mydomain.com/site1.php as the referrer, which is no good. So, my problem lies with the script not redirecting fast enough. My page loads, and then it redirects, but it is very slow. I don't want them to see the page if possible, but it still needs to pass on the referrer.


    <?php
    
    $site1 = "http://www.mydomain.com/site1.php";
    $affiliate_link = "http://www.mydomain.com/page/";
    
    if($_SERVER['HTTP_REFERER'] == $site1)
    {
    	echo "<body onload=\"javascript:frmClickTracking.submit();\">";
    	echo "<form action=\"" . $affiliate_link . "\" method=\"post\" name=\"frmClickTracking\">";
    	echo "</form>";
    }
    
    ?>
    Code (markup):
     
    hexxer, Mar 28, 2009 IP
  2. Stylesofts

    Stylesofts Peon

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hello,

    So u need to redirect right.


    so here what u can do

    <?php
    
    $site1 = "http://www.mydomain.com/site1.php";
    $affiliate_link = "http://www.mydomain.com/page/";
    
    if($_SERVER['HTTP_REFERER'] == $site1)
    {
    	echo "<script>location.href='$affiliate_link '</script>";
    }
    else
    {
    
    ////////////You can write things here...display the other contents which you want to show when the condition is false//////////////
    
    }
    
    ?>
    PHP:
    Regards,
    Stylesofts Developing Team
     
    Stylesofts, Mar 29, 2009 IP
  3. TheOnly92

    TheOnly92 Peon

    Messages:
    17
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I remember that you can send referer using headers in this way:

    
    header('Referer:'.$site1);
    
    Code (markup):
    But not sure if it will work. If you want to use javascript, you should not put onload as it will wait till the page loads then execute.
     
    TheOnly92, Mar 29, 2009 IP
  4. hexxer

    hexxer Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    43
    #4
    WOW! Thank you very much guys! I ended up using StyleSofts's code. I literally spent hours messing/searching for code. My hats off to you!
     
    hexxer, Mar 29, 2009 IP
  5. Stylesofts

    Stylesofts Peon

    Messages:
    64
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    :D No worries...We are here to help

    :)
     
    Stylesofts, Apr 3, 2009 IP