Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP redirect by IP Address [help with Code]

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #37432
    Al3ks
    Participant

    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:

    $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

    #100358
    nonsalant
    Participant

    Try using $_SERVER instead of $REMOTE_ADDR:

    $ip = $_SERVER;
Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.