Jump to content

How can I make this more efficient


devWhiz

Recommended Posts


<?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

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!

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.