CBG Posted March 3, 2010 Share Posted March 3, 2010 Hi, I want the below code to check for 2 IP's that are allowed. This is the code I got so far. The below code allows 1 IP to view, however I would like to have 2 IP's to be able to view and not directed to offline.php <?php $offip1 = 'XXX.XXX.XXX.XXX'; //Offline IP 1 allowed to view $offip2 = 'XXX.XXX.XXX.XXX'; //Offline IP 2 allowed to view $offstatus = 'offline'; //Offline-Online Status if (strcmp($_SERVER['PHP_SELF'],"/offline.php") != 0) { if ( $offip1 != getenv('REMOTE_ADDR')){ if ( $offstatus == 'offline' ) { header ('location: offline.php'); } } } echo 'You are viewing when in offline mode'; ?> Link to comment https://forums.phpfreaks.com/topic/193987-offline-allow-2-ips-to-view-rest-redirect/ Share on other sites More sharing options...
CBG Posted March 3, 2010 Author Share Posted March 3, 2010 Will this do it <?php $offip1 = 'XXX.XXX.XXX.XXX'; //Offline IP 1 allowed to view $offip2 = 'XXX.XXX.XXX.XXX'; //Offline IP 2 allowed to view $offstatus = 'offline'; //Offline-Online Status $allow[0]=$offip1; $allow[1]=$offip2; if (in_array($_SERVER['REMOTE_ADDR'],$allow)) { echo 'You are viewing when in offline mode'; }else{ if ( $offstatus == 'offline' ) { header ('location: offline.php'); } } ?> Link to comment https://forums.phpfreaks.com/topic/193987-offline-allow-2-ips-to-view-rest-redirect/#findComment-1020841 Share on other sites More sharing options...
inversesoft123 Posted March 3, 2010 Share Posted March 3, 2010 You must set browser cookies instead. Because ip addresses are not fixed they may change each time when you connect to net. So it raises security risks. Link to comment https://forums.phpfreaks.com/topic/193987-offline-allow-2-ips-to-view-rest-redirect/#findComment-1020842 Share on other sites More sharing options...
CBG Posted March 3, 2010 Author Share Posted March 3, 2010 This, is just a quick way to test, of what I want the IP's will be set in the database from the admin or the script I am using. So there should be no security risk. Link to comment https://forums.phpfreaks.com/topic/193987-offline-allow-2-ips-to-view-rest-redirect/#findComment-1020846 Share on other sites More sharing options...
inversesoft123 Posted March 3, 2010 Share Posted March 3, 2010 $ip = $_SERVER['REMOTE_ADDR']; if($ip == "xxx.xxx.xxx.xxx" || $ip == "xxx.xxx.xxx.xxx") { //show this } else { //show this eg: offline } Link to comment https://forums.phpfreaks.com/topic/193987-offline-allow-2-ips-to-view-rest-redirect/#findComment-1020848 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.