PHP redirect depending on IP address

I need my PHP to direct different IPs to different webpages. I have done it but it seems to not be working, it just directs everyone to the link that’s at the bottom of the list.

Here is my PHP:

<?php $ip=$_SERVER['REMOTE_ADDR']; switch ($ip) { default: header( 'Location: /index2.html' ) ; case "192.168.2.4": header( 'Location: /people/4.html' ); case "192.168.2.15": header( 'Location: /people/2.html' ); case "192.168.2.3": header( 'Location: /people/1.html' ); case "192.168.2.13": header( 'Location: /people/1.html' ); case "192.168.2.2": header( 'Location: /people/1.html' ); case "192.168.2.9": header( 'Location: /people/1.html' ); case "192.168.2.10": header( 'Location: /people/4.html' ); case "192.168.2.6": header( 'Location: /people/5.html' ); case "192.168.2.8": header( 'Location: /people/1.html' ); case "192.168.2.5": header( 'Location: /people/3.html' ); } ?>

thanks

You must break after each case:

[php]<?php
$ip=$_SERVER[‘REMOTE_ADDR’];

switch ($ip) {
default:
header( ‘Location: /index2.html’ ) ;
break;
case “192.168.2.4”:
header( ‘Location: /people/4.html’ );
break;
case “192.168.2.15”:
header( ‘Location: /people/2.html’ );
break;
case “192.168.2.3”:
header( ‘Location: /people/1.html’ );
break;
case “192.168.2.13”:
header( ‘Location: /people/1.html’ );
break;
case “192.168.2.2”:
header( ‘Location: /people/1.html’ );
break;
case “192.168.2.9”:
header( ‘Location: /people/1.html’ );
break;
case “192.168.2.10”:
header( ‘Location: /people/4.html’ );
break;
case “192.168.2.6”:
header( ‘Location: /people/5.html’ );
break;
case “192.168.2.8”:
header( ‘Location: /people/1.html’ );
break;
case “192.168.2.5”:
header( ‘Location: /people/3.html’ );
break;
}

?>[/php]

How are you testing this out? The IP addresses you list are all sub IP’s, so that should be interesting to see how your “outside” computers are connecting to the page. My next thing would be, why are you redirecting to a different page? Yes, it has its use, but the way you are doing it seems out of place.

Sponsor our Newsletter | Privacy Policy | Terms of Service