Quick PHP Q - Redirecting

Discussion in 'PHP' started by Sdawg, Feb 4, 2011.

  1. #1
    Hi,

    Wondering how I can do this. I'm good at marketing, but appaling at code so take it easy on me ha.

    I want to redirect a user based on their IP. So, if IP is X, they go to Site A, if anything else, go to Site B.

    Any ideas?
     
    Sdawg, Feb 4, 2011 IP
  2. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #2
    $ip = getenv("REMOTE_ADDR");
    switch ($ip)
    {
      case "81.81.91.81":
        header("Location:hahaha.php");
      break;
      case "81.91.81.81":
        header("Location:lol.php");
      break;
    }
    PHP:
    Hope I helped :)
     
    G3n3s!s, Feb 4, 2011 IP
  3. Sdawg

    Sdawg Active Member

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Appreciate the reply, thanks!

    I added that, here is my code. It doesn't seem to be working:

    <?
    
    $ip = getenv("REMOTE_ADDR");
    switch ($ip)
    {
      case "66.112.215.70":
        header("Location:http://google.com");
      break;
    }
    
    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: http://yahoo.com" );
    ?>
    
    
    
    
    PHP:

    What the above is meant to do is redirect people who visit my URL "test.com/redirect.php" to Yahoo.com, with the exception of that IP which should be taken to google.com
     
    Sdawg, Feb 4, 2011 IP
  4. Simple Link Media

    Simple Link Media Peon

    Messages:
    38
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    switch ($_SERVER['REMOTE_ADDR'])
    {
    
        case "127.0.0.1":
    
            header("Location: http://www.google.co.uk");
    
            break;
    
        default:
    
            header("Location: http://www.yahoo.com");
    
            break;
    
    }
    PHP:
     
    Simple Link Media, Feb 4, 2011 IP
    Sdawg likes this.
  5. Sdawg

    Sdawg Active Member

    Messages:
    112
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #5

    Works a charm, thanks a lot!!
     
    Sdawg, Feb 4, 2011 IP