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 b5de7e4466 add Libre Licence 5 months ago
README.md add Libre Licence 5 months ago
Screenshot.png screenshot border 11 months ago
forbidden.css initial 11 months ago
forbidden.html initial 11 months ago
forbidden.php initial 11 months ago
forbidden.png initial 11 months ago
htmlforbidden.php update htmlforbidden 11 months ago
logo.png updated pngs 11 months ago
script.js initial 11 months ago


PHP Spam Block

A simple PHP function banning unwanted visitors from your website.


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.


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

if (in_array ($_SERVER['REMOTE_ADDR'], $deny)) {
	header('HTTP/1.0 403 Forbidden');


You can also use it within all your PHP files:


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:

	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:


$deny = array("","::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("","::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.


You may freely use PHP Spam Block's source code according to my Libre Licence. A link to my repo as the original source would be great 😎