PHP Redirect + Referer

Discussion in 'PHP' started by abstroose, Nov 24, 2008.

  1. #1
    I need help with a redirect script. Basically, I need to redirect the user to a random page which then requires the referer (which will be the redirect page). The problem is the redirect method I'm using doesn't carry the referer. I did manage to use an alternative Javascript redirect which carried the referer but it didn't work on Firefox!

    Here's the code from REF.PHP

    
    <?php
    srand ((double) microtime() * 1000000);
    $ref = array("/affiliate-marketing-basics.php","/affiliate-marketing-leads.php","/affiliate-markets-saturation.php","/article-marketing-to-help-in-affiliate-marketing.php","/tracking-affiliate-referrals.php","/web-hosting-affiliate-programs.php");
    $rand_url = array_rand($ref,6);
    $url = $ref[$rand_url[0]];
    
    echo('<meta http-equiv="refresh" content="0;url='.$url.'">'); 
    ?>
    
    Code (markup):
    Any help would be much appreciated.
     
    abstroose, Nov 24, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Is there some reason you can't do a standard redirect:

    
    srand ((double) microtime() * 1000000);
    $ref = array("/affiliate-marketing-basics.php","/affiliate-marketing-leads.php","/affiliate-markets-saturation.php","/article-marketing-to-help-in-affiliate-marketing.php","/tracking-affiliate-referrals.php","/web-hosting-affiliate-programs.php");
    $rand_url = array_rand($ref,6);
    $url = $ref[$rand_url[0]];
    
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: mysite.com/".$url);
    exit();
    
    
    PHP:
     
    jestep, Nov 24, 2008 IP
  3. atlantaazfinest

    atlantaazfinest Peon

    Messages:
    389
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #3
    One of yours problems you might run into is that the user's browser won't pass the referer part of the header which makes that part of the script use less what you might want to do is pass a GET variable with the page it came from somehow.
     
    atlantaazfinest, Nov 24, 2008 IP
  4. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #4
    Just a small addition: instead of this

    you could use only one line with http response code specified

    
    header("Location: mysite.com/".$url, true, 301);
    
    PHP:
    and PHP will do the rest.
     
    wmtips, Nov 24, 2008 IP