Jump to content

[SOLVED] ban hosts problem


adv

Recommended Posts

hello

i`ve tried to create a script that when hosts that are in the array()  will show a error page but i`m stuck

after that i want to show the page if the host is not in the array()

 

here`s the code

<?php

$uri = $_SERVER["REQUEST_URI"];
$ipserver = $_SERVER["SERVER_ADDR"];
$resuelveserver = gethostbyaddr($ipserver);

$IP = getenv("REMOTE_ADDR");
$host = gethostbyaddr($IP);
$banhosts = array(".us","email",".cc",".de",".hk");
$x = count($banhosts);

$notfound = "<HTML><HEAD>
<TITLE>404 Not Found</TITLE>
</HEAD><BODY>
<H1>Not Found</H1>
The requested URL $uri was not found on this server.<P>
<HR>
<ADDRESS>Apache/1.3.34 Server at $resuelveserver Port 80</ADDRESS>
</BODY></HTML>";


for ($y = 0; $y < $x; $y++) {
   if (strpos($host ,$banhosts[$y])=== true) {
     echo $notfound;
   }
   
}


?>

after the if i`ve tried alot of  things but nothing

 

elseif (strpos($host ,$banhosts[$y])=== false) { echo "you are allowed here";}

but it doesn`t echo nothing

 

elseif (!strpos($host ,$banhosts[$y])) { echo "you are allowed here";}

same here

 

i`ve tried directly 

 

else { echo "you are allowed here"; } 

but it keeps echoing even if the host is in the banhosts array()

Link to comment
https://forums.phpfreaks.com/topic/102054-solved-ban-hosts-problem/
Share on other sites

pff it still doesn`t work :

 


$banhosts = array(".us","email",".cc",".de",".hk");
for ($y = 0; $y < $x; $y++) {
   if (strpos($host ,$banhosts[$y]) !== false) 
  {
     echo $notfound;
   }
   else { echo "ad"; } 
}

 

and i tried with my ip that is in the $banhosts

but if i use the else { echo "ad"; }

 

 

adad
Not Found
The requested URL /test22.php was not found on this server.

Apache/1.3.34 Server at localhost Port 80

i don`t know what is wrong

 

if i try with only the if statement and my host in in the $banhosts it works but if my host is not in the $banned hosts it doesnt show nothing

This seems to work in my server. Try it out on your server

 

<?php

//$uri = $_SERVER["REQUEST_URI"];
//$ipserver = $_SERVER["SERVER_ADDR"];
//$resuelveserver = gethostbyaddr($ipserver);

//$IP = getenv("REMOTE_ADDR");
//$host = gethostbyaddr($IP);

// For debugging
$host = "239-12-92-86.rdsnet.ro.";
$banhosts = array(".us","email",".cc",".de",".hk", ".ro");
$x = count($banhosts);

//$notfound = "<HTML><HEAD>
//<TITLE>404 Not Found</TITLE>
//</HEAD><BODY>
//<H1>Not Found</H1>
//The requested URL $uri was not found on this server.<P>
//<HR>
//<ADDRESS>Apache/1.3.34 Server at $resuelveserver Port 80</ADDRESS>
//</BODY></HTML>";


var_dump($banhosts);

for ($y = 0; $y < $x; $y++) {
   $result = strpos($host ,$banhosts[$y]);
   echo "Result for {$banhosts[$y]}: " . var_dump($result) . "\n";
   if ($result !== false) 
   {
     // echo $notfound;
     echo "Banned Host";
   }
   
}


?>

thanks alot dptr for helping me

but i got still a problem

 

<?php

$uri = $_SERVER["REQUEST_URI"];
//$ipserver = $_SERVER["SERVER_ADDR"];
$resuelveserver = gethostbyaddr($ipserver);

//$IP = getenv("REMOTE_ADDR");
//$host = gethostbyaddr($IP);

// For debugging
$host = "239-12-92-86.rdsnet.ro.";
$banhosts = array(".us","email",".cc",".de",".hk",".ro");
$x = count($banhosts);

$notfound = "<HTML><HEAD>
<TITLE>404 Not Found</TITLE>
</HEAD><BODY>
<H1>Not Found</H1>
The requested URL $uri was not found on this server.<P>
<HR>
<ADDRESS>Apache/1.3.34 Server at $resuelveserver Port 80</ADDRESS>
</BODY></HTML>";


//var_dump($banhosts);

for ($y = 0; $y < $x; $y++) {
   $result = strpos($host ,$banhosts[$y]);
   //echo "Result for {$banhosts[$y]}: " . var_dump($result) . "\n";
   if ($result !== false) 
   {
      echo $notfound;
     //echo "Banned Host";
   }
  // this is what i get wrong .. nothing works 
  // elseif ($result === false) { header("location:test.php"); }
  // else { header("location:test.php"); }
  //if (!$result) { header("location:test.php"); }
}


?>


 

i can`t get it working on the redirect

if $result is false to be redirected  ...

it keeps redirecting me directly ..

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.