|
|
|
|
![]() ![]() |
Jun 25 2007, 03:01 AM
Post
#1
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 60 Joined: 25-February 07 From: Somewhere Your Not! Well... Maybe your here. Who Knows? Member No.: 39,197 |
Hello, I did some search's to see if anyone had covered this apparently not! So ok! Lets set up a Ip Site blocker using php and mysql
The First thing we are going to do is make the form that is actually blocking the site. Note: You Must have this in a PHP file to work, it must be at the VERY TOP!!!!! CODE <?php $vip = $_SERVER['REMOTE_ADDR']; include "config.php"; ############################## # See if the Ip is in the blocked list # ############################## $get_info = mysql_query("SELECT * FROM blocked WHERE ip = '$vip'"); $do_block = mysql_fetch_array($get_info); ############################################ # Now we are just checking to see if we need to block the user # ############################################ if( $do_block['ip'] == "$vip" ){ die("Sorry! Your Ip has been blocked from viewing our sites content"); } ?> The above just save it however you want to... I would recommend ipblocklist.php before that works we need to create the table inside of a database that will have the ip's stored inside of them So in phpMyAdmin or your MySql Query Window type in CODE USE 'databasename'; Excute it... CODE CREATE TABLE blocked( id int not null auto_increment primary key, ip varchar(15), added datetime); Excute... Now you are set up! Ok, Good Job on the MySql Database set up... Now, we need to create a config file which will store how we are connecting and what database we are using CODE <?php ######################### # Config File # ######################### $dbhost = "localhost"; // This is your database host name usally localhost $dbuser = "user"; // This is your database user name... $dbpass = "pass"; // this is your password used to login to the database $dbname = "database"; // this is your database name. ########################## # Edit the above to suit your needs ## ########################## $conn = mysql_connect("$dbhost","$dbuser","$dbpass"); mysql_select_db("$dbname", $conn ); ?> Then Your Done... I would save this as config.php because thats what we imported into our ip checker file (e.g. inlcude "config.php"; ) Ok, as I said you need to put this line of code on your first line after <?php or if you are using session_start(); after that it's should like this CODE <?php include "ipblocklist.php"; // The rest of your code ?> Now, it's time to make a admin type area so you can add or remove blocked Ip's... CODE <?php session_start(); ##################### # Get the Config File # ##################### include "config.php"; ######################### # Set the admin credentials # ######################### $admin = 'admin'; $pass = 'password'; $s_user = $_POST["admin"]; $s_pass = $_POST["pass"]; if( $ses_user <= " " ){ ######################### # Admin Login Form # ######################### echo "<form action='ipadmin.php' method='post'>"; echo "Admin: <input type='text' name='admin'><br>"; echo "Pass: <input type='password' name='pass'><br>"; echo "<input type='submit' value='Login'>"; echo "</form>"; } if( $s_user == $admin and $s_pass == $pass ){ $ses_user = $_SESSION['admin'] = $s_pass; $go = 1; } if( $go = 1 ){ echo "Add a Ip to the Blocked List"; echo "<form action='ipadmin.php' method='post'>Ip: <input type='text' name='ip'><input type=submit value='Block Ip'></form>"; } if( $_POST["ip"] > " " ){ $ip2 = $_POST["ip"]; echo "Are you sure you want to block $ip2"; echo "<form action='ipadmin.php' method='post'><input type='hidden' name='ip2' value='$ip2'><input type='submit' name='block' value='yes'>"; } if( $_POST["block"] == "yes" ){ mysql_query("INSERT INTO blocked SET ip = '$ip2' added = NOW()") or die("Could not Block Ip, MySql Error"); } echo "<center>Remove Blocked Ips<br><br>"; echo "<form action='ipadmin.php' method='post'><select name='remove'><option value=''>Select One</option>"; $ips = mysql_query("SELECT * FROM blocked"); while( $showips = mysql_fetch_array($ips)){ $ip_value = $showips['ip']; echo "<option value='$ip_value'>$ip_value</option>"; } echo "<input type='submit' value='RemoveIp' name='Remove Ip'>"; echo "</form>"; if( $_POST["Remove Ip"] == "RemoveIp" ){ $del_ip = $_POST['remove']; mysql_query("DELETE FROM blocked WHERE ip = '$del_ip' LIMIT 1"); echo "The Ip $del_ip has been removed from the blocked list!"; } ?> OK now save that above as ipadmin.php Everything Should work succesfully any question |
|
|
|
Jun 25 2007, 04:10 AM
Post
#2
|
|
|
Desperately seeking "any key" to continue... ![]() Group: Admin Posts: 3,438 Joined: 23-April 05 From: Trap17 storage box Member No.: 6,042 |
This tutorial is more of hands on coding. Trap17 cpanel offers easy one step IP block manager for those who are seeking an easier execution.
|
|
|
|
Jun 25 2007, 04:23 AM
Post
#3
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 60 Joined: 25-February 07 From: Somewhere Your Not! Well... Maybe your here. Who Knows? Member No.: 39,197 |
Yeah, I mostly did this for people who does not have a Ip Blocker installed on there machine... It's basicly the same way but somethings, are diffrent...
|
|
|
|
Jun 25 2007, 05:21 AM
Post
#4
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 3,882 Joined: 24-July 05 From: In Trouble Again... still? Member No.: 9,787 ![]() |
I am able to get an IP blocked using this script, but the ipadmin.php is giving an error when adding or removing ip's.
I have a good db connection, since it blocks the IP on my localhost, but I had to add the ip using phpadmin in order to acquire the block. Any suggestions? Is there a working link for this script available? |
|
|
|
Jul 3 2007, 01:42 AM
Post
#5
|
|
|
Member [Level 1] ![]() ![]() ![]() ![]() Group: Members Posts: 60 Joined: 25-February 07 From: Somewhere Your Not! Well... Maybe your here. Who Knows? Member No.: 39,197 |
Sorry, I couldnt find my post, I am going to fix it right now... allow me until tomorrow to post what I fixed
|
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 27th July 2008 - 01:17 AM |