Posts: 2,216
Threads: 187
Joined: Jul 2011
01-11-2012, 03:08 PM
(This post was last modified: 01-12-2012, 05:56 AM by BreShiE.)
I was just messing around with a little PHP, and I thought of this way to block access to certain IP addresses from accessing your web page. I originally made it to make it so people who aren't me cannot view a certain page, but just changed it from if not to if and there you have it.
PHP Code:
<html>
<head>
<title>Banned IP</title>
</head>
<?php
If ($_SERVER['REMOTE_ADDR'] == "1.1.1.1"){ // Replace 1.1.1.1 with the IP you want to block access
echo 'Your IP is banned from accessing this webpage.<br /><br />';
}
?>
</html>
Posts: 9
Threads: 1
Joined: Jan 2012
Reputation:
0
You could just ban the IP in your cPanel, if you use cPanel.
Posts: 2,216
Threads: 187
Joined: Jul 2011
01-12-2012, 12:42 AM
(This post was last modified: 01-12-2012, 12:43 AM by BreShiE.)
(01-11-2012, 05:33 PM)AceInfinity Wrote: You're going to add this manually for every IP you have to ban though?
You could also go with an .htaccess method
This is just a quick way of banning people from one page, if you wanted to do it for all of them you can make that a lot easier too. Put the code into a file called something like 'inc.php' then just:
PHP Code:
<?php
require 'inc.php'; // Do this for every page, and you can copy and paste it to make it even quicker.
?>
Simples.
(01-11-2012, 07:32 PM)Laugh Wrote: (01-11-2012, 07:27 PM)lovetospooge Wrote: You could just ban the IP in your cPanel, if you use cPanel.
But he is telling us how to do it with PHP.
Exactly, thanks.
Posts: 1,782
Threads: 167
Joined: Oct 2009
Reputation:
71
Title should have had php in it perhaps.
To stop people saying .htaccess as thats the better option i feel.
But a good post. Update the thread title i think mate.
Posts: 2,216
Threads: 187
Joined: Jul 2011
Edited the title and included PHP in it, hopefully people wont get the wrong idea now.
Posts: 109
Threads: 2
Joined: Dec 2011
Reputation:
0
Even though, I love the .htaccess method.
Posts: 284
Threads: 16
Joined: Oct 2010
Reputation:
11
great share mate.
i didn't know that.
thanks.