Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Mar 2011
    Thanked 0 Times in 0 Posts

    Script that alters what page is shown based on IP?

    Anyone know of a script that shows a different page based upon a users IP address?


  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    London, England
    Thanked 2,573 Times in 2,551 Posts
    Javascript by itself cannot capture an IP address, you need to use server-side scripting such as PHP:-

    <script type = "text/javascript">
    var ip = "<?php echo $_SERVER['REMOTE_ADDR']?>";
    // redirect if a certain IP address matches
    The file should either have a .php suffix or be parsed for PHP.

    See also http://www.javascriptkit.com/script/...isplayip.shtml for a similar script using SSI.

    Be aware that many IP addresses are dynamic and may change at quite frequent intervals. Also, if the user disables Javascript in his browser the script becomes futile. You should prefer to use server-side scripting.

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 01-04-2012 at 03:24 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts