...

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



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

Thanks

Philip M
01-04-2012, 01: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
</script>

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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum