View Full Version : Script that alters what page is shown based on IP?

01-04-2012, 12:57 PM
Anyone know of a script that shows a different page based upon a users IP address?


Philip M
01-04-2012, 02:55 PM
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/script2/displayip.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.