Log and blocking visitors to your site

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
polarbear1981
Forum Newbie
Posts: 1
Joined: Tue Dec 27, 2011 7:40 am

Log and blocking visitors to your site

Post by polarbear1981 »

// I have write some code but I want to improve this code so maby somebody have some suggestions to improve this code

Code: Select all

<?
$banned[0]="82.100.220.59"; 
$banned[1]="119.27.62.254";
if (in_array($_SERVER['REMOTE_ADDR'],$banned)) 
{ 
echo "<b>You have no permission to visit this site.</b>"; 

exit;
}
?>

<html>
<h1>voorbeeld.com </h1>
<br>

This site is under construction <br>
Regards moderator. <br><br>

<A HREF="http://www.voorbeeld.com/contact.php">Contact</A> <br><br>
</html>

<?
 
$ip= $_SERVER['REMOTE_ADDR'] . "   -  index.php - " ;
$date= date('D M j G:i:s T Y') . " -";
$data= $date . " ". $ip;


$logfile = '/home/polarbear/domains/voorbeeld.com/public_html/log.php'; 

if (!$handle = fopen($logfile, 'a+')) { 
   die("Failed to open log file"); 
} 

if (fwrite($handle, $data ) === FALSE) { 
    die("Failed to write to log file"); 
} 
   
fclose($handle); 
?>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Log and blocking visitors to your site

Post by Christopher »

Looks fine. What part do you want to improve -- the blocking or logging?
(#10850)
Post Reply