A PHP function banning unwanted visitors from your website.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
pixelcode 8e96d8ae5a update README 3 months ago
README.md update README 3 months ago
Screenshot.png updated pngs 3 months ago
forbidden.css initial 3 months ago
forbidden.html initial 3 months ago
forbidden.php initial 3 months ago
forbidden.png initial 3 months ago
htmlforbidden.php update htmlforbidden 3 months ago
logo.png updated pngs 3 months ago
script.js initial 3 months ago

README.md

PHP Spam Block

A simple PHP function banning unwanted visitors from your website.

Screenshot

Use it inside a PHP file

If you use PHP files instead of HTML ones you can use this script. It checks whether the user’s IP address is contained by an array with all spammers you want to block. If the user is a spammer, PHP will include your custom ‘forbidden’ page.

<?php

$deny = array("127.0.0.1","::1"); // IP addresses of the unwanted guests

if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
	header('HTTP/1.0 403 Forbidden');
	include('forbidden.html');
	exit();
}

?>

You can also use it within all your PHP files:

include('forbidden.php');

Use it inside HTML files with Ajax

If you’re using HTML files instead of PHP ones you can host the modified version “htmlforbidden.php” of the PHP script which answers Ajax requests. Your script.js asks your server whether the user is a spammer. If that’s true, he’ll be redirected to forbidden.html:

$.ajax({
	type: "POST",
	url: 'htmlforbidden.php',
	data: {"isthis":"spam"},
	success: function(response){
		var jsonData = JSON.parse(response);
		if (jsonData.spam == "ja"){
			window.location.href = 'forbidden.html';
		}
    }
});

Your htmlforbidden.php file just echos the result:

<?php

$deny = array("127.0.0.1","::1");

if (in_array($_SERVER['REMOTE_ADDR'], $deny)) {
	echo json_encode(array('spam' => 'ja'));
} else {
	echo json_encode(array('spam' => 'nein'));
}

?>

How to list IP addresses

Place all your malicious IP addresses inside the $deny = array("127.0.0.1","::1"); array. Each of them is surrounded by “". They’re seperated by commas.

For example, if you want to ban Google from your website you can use Kromonos’ IP address list.

License

You may use PHP Spam Block’s source code without explicit permission but a link to my repo would be great of course 😎