devWhiz Posted May 15, 2011 Share Posted May 15, 2011 <?php $IPaddress = $_SERVER['REMOTE_ADDR']; if(stristr($IPaddress, "123.456.58.451") || stristr($IPaddress, "123.126.456.10") || stristr($IPaddress, "123.126.456.10")) { echo "<center><b><i>CWB permits you to views this page...</i></b></center></br>"; echo '<center><b><font size="5">'.$IPaddress.'</font></b></center>'; } else { echo "<center><b>CWB DOES NOT PERMIT YOU TO VIEW THIS PAGE</b></center>"; } exit; ?> how do I make it to where I dont have to keep adding on to if(stristr($IPaddress, "123.456.58.451") || stristr($IPaddress, "123.126.456.10") || stristr($IPaddress, "123.126.456.10")) Link to comment https://forums.phpfreaks.com/topic/236444-how-can-i-make-this-more-efficient/ Share on other sites More sharing options...
anupamsaha Posted May 15, 2011 Share Posted May 15, 2011 Try this: $IPArray = array("123.456.58.451", "123.126.456.10", "123.126.456.10"); if (in_array($IPaddress, $IPArray)) { // If found the IP from the array, do whatever you like to do } else { // If not found the IP from the array, do whatever you like to do } .... Thanks! Link to comment https://forums.phpfreaks.com/topic/236444-how-can-i-make-this-more-efficient/#findComment-1215586 Share on other sites More sharing options...
PaulRyan Posted May 15, 2011 Share Posted May 15, 2011 <?php $allowed = array('123.456.58.451','123.126.456.10','123.126.456.10'); if(in_array($_SERVER['REMOTE_ADDR'],$allowed)) { echo "<center><b><i>CWB permits you to views this page...</i></b></center></br>"; echo '<center><b><font size="5">'.$IPaddress.'</font></b></center>'; } else { echo "<center><b>CWB DOES NOT PERMIT YOU TO VIEW THIS PAGE</b></center>"; } ?> Regards, PaulRyan. Link to comment https://forums.phpfreaks.com/topic/236444-how-can-i-make-this-more-efficient/#findComment-1215588 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.