Grow your CSS skills. Land your dream job.

PHP redirect by IP Address [help with Code]

  • # March 31, 2012 at 11:00 am

    Hi people,

    I am trying to redirect people on my site depending on their IP Address, and more specifically everyone who’s IP doesn’t match the one specified in the array, in my code.

    Here is my code:

    < ?php
    $allowed = array("94.171.121.121");
    $ip = $REMOTE_ADDR;
    if(!in_array($ip, $allowed))
    {
    header("Location: http://www.google.co.uk); /* Redirect browser */
    /* Make sure that code below does not get executed when we redirect. */
    exit;
    }
    else
    {

    }
    ?>

    The problem is it redirects everyone even the specified IP address.
    Any tips how to make it work?

    Regards,
    Aleksander

    # March 31, 2012 at 1:00 pm

    Try using $_SERVER instead of $REMOTE_ADDR:

    $ip = $_SERVER;
Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.

*May or may not contain any actual "CSS" or "Tricks".