Basic ip log and blocking

Links for php scripts

Moderators: macek, egami, gesf

Xmen
New php-forum User
New php-forum User
Posts: 1
Joined: Mon May 21, 2012 8:53 am

Basic ip log and blocking

Postby Xmen » Sun May 27, 2012 6:15 am

//Index.php
<?

$banned[0]="x.x.x.x"; // Er must always 1 ip be banned otherwise you get a error.
$banned[1]="193.172.46.220"; //Banned ip


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

exit;
}
?>

<html>
<br><br>

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


</html>

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

// echo "<b>IP Address= $ip</b>";

$logfile = '/home/domains/yoursite.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);
?>

// end of script





// Log.php start from logfile

<?
header( 'Location: http://www.yoursite.com' ) ; // This code blocks acces from the webbrowser
// to the log file
// Now you can only visit the log file from your Admin
?>

// The log below is a example from logging you can delete this log

Sun May 27 16:08:14 CEST 2012 - 199.19.249.196 - index.php - Sun May 27 16:08:14 CEST 2012 - 83.232.148.202 - index.php -

Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest