1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

If Referring URL = X Then Redirect Here, If Y Then Redirect There???

Discussion in 'PHP & Perl' started by gimme4free, Dec 17, 2008.

  1. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
  2. blackhatttt

    blackhatttt Regular Member

    Joined:
    Apr 11, 2008
    Messages:
    221
    Likes Received:
    19
    Here you go:

    PHP:
    <?

    $referer $_SERVER['HTTP_REFERER'];
    if(
    $referer == "http://www.blackhatworld.com")//the referer you want to base your redirects on
        
    {
            
    header("location:http://www.google.com");//if condition is true
        
    }
    else
        {
            
    header("location:http://www.yahoo.com");//if condition is false
        
    }

    ?>
     
    • Thanks Thanks x 1
  3. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    Thanks a lot, Im using this one now:

    PHP:
    <?php

    $match 
    false;
    $sites = array("blackhatsite.com");

    if(
    strlen($_SERVER['HTTP_REFERER']))
    {
        
    $referer parse_url($_SERVER['HTTP_REFERER']);
               
        
    $referer['host'] = str_replace("www."""strtolower($referer['host']));

        
    $match in_array($referer['host'], $sites);
    }

    if(
    $match)
    {

    ?>
    <?php
     
    echo '<meta http-equiv="refresh" content="0;url=http://www.yoursite.com/affiliateoffer.php">';
     
    ?>
    <?php
    }
    else
    {
    ?>
    <?php
     
    echo '<meta http-equiv="refresh" content="0;url=http://www.homepage.com/">';
    ?>
    <?php
    }
    ?>
    Probably a bit messy but it works lol
     
  4. ultimatium1

    ultimatium1 Junior Member

    Joined:
    Oct 10, 2008
    Messages:
    107
    Likes Received:
    19
    Lol, Array for 1 value ^^ Not really needed.

    Still, If it aint broke dont fix it
     
  5. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    Yeah, I used it from a site that incorporated 2 referring URL's, do you know how I could switch it back to one? Or would you recommend the first PHP script that you posted here?
     
  6. blackhatttt

    blackhatttt Regular Member

    Joined:
    Apr 11, 2008
    Messages:
    221
    Likes Received:
    19
    Hmm from what I see both scripts will do pretty much the same thing. But you script seem way to completed than it should be. So just use mind you will do find. Since you only have 1 value.
     
    Last edited: Dec 17, 2008
  7. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    Thanks for the input Gen, could you help me out for a few mins at some point just to determine the referring URL on an iFrame script I have made and to see if you can find the affiliate link :p
     
  8. ultimatium1

    ultimatium1 Junior Member

    Joined:
    Oct 10, 2008
    Messages:
    107
    Likes Received:
    19
    Do you need to see the referer?
    If so, in your iframe page, add

    PHP:
    <?php
    echo $_SERVER['HTTP_REFERER'];
    ?>
    As for this, You can use

    PHP:
    <?php

    if($_SERVER['HTTP_REFERER'] == "http://site url")
    {
           
    Header ("Location: http://goherewatever/");
    } else {
           
    Header ("Location: http://gohereinsteadcom/");
    }

    ?>
     
  9. fatboy

    fatboy Elite Member

    Joined:
    Aug 13, 2008
    Messages:
    1,618
    Likes Received:
    3,227
    Occupation:
    Retired
    Location:
    Old Peoples Home
    I always use the switch case in PHP - beats a shed load of IF statements....but that array is isn't a bad idea as well....
     
  10. simplybebop

    simplybebop Regular Member

    Joined:
    Oct 24, 2008
    Messages:
    371
    Likes Received:
    177
    Location:
    Greesnboro, NC
    Could you possibly do this with 250 different urls?
     
  11. gimme4free

    gimme4free Executive VIP Jr. VIP Premium Member

    Joined:
    Oct 22, 2008
    Messages:
    1,879
    Likes Received:
    1,932
    You mean for a rotator script sort of thing?
     
  12. ultimatium1

    ultimatium1 Junior Member

    Joined:
    Oct 10, 2008
    Messages:
    107
    Likes Received:
    19
    Ofcourse, But a array would be better for that, Or if the urls are numerically incremented just 1 trim variable with the number at the end.