Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Ip Blocking Php Script!, Stop the bad guys before they stop you.
cwconline
post 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
Go to the top of the page
 
+Quote Post
BuffaloHELP
post Jun 25 2007, 04:10 AM
Post #2


Desperately seeking "any key" to continue...
Group Icon

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.
Go to the top of the page
 
+Quote Post
cwconline
post 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...
Go to the top of the page
 
+Quote Post
jlhaslip
post 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 Icon

Group: [MODERATOR]
Posts: 3,882
Joined: 24-July 05
From: In Trouble Again... still?
Member No.: 9,787
Spam Patrol



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?
Go to the top of the page
 
+Quote Post
cwconline
post 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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Script: Php Jukebox(4)
  2. Parse: Error Unexpected T_lnumber(4)
  3. Transfer Variables To Another Php Script(8)
  4. Watermark Your Image With Simple Php Script(34)
  5. Script That Tracks The User Status(4)
  6. Wappychat_oldskool(15)
  7. Php Search Engine Script For Mysql Database(11)
  8. Free Auction Script(6)
  9. Wappy Buddy V1.10 - Tibia Gold Edition By Wappy & Jon Roig(3)
  10. What Kind Of Script Do You Need ?(15)
  11. Creatting A Playlist Through Php(5)
  12. Is This A Good Script?(9)
  13. Html Code Tester. Online Script(15)
  14. Php Sessions And Post Variables Issues(1)
  15. Will This Code Work(5)
  1. Php Downloads Script(3)
  2. Script Help Required: Undefined Variable(3)
  3. Script Not Working(6)
  4. Library Script(6)
  5. How Would I Go About Making A Simple "counting" Script?(3)
  6. Forum Script(3)
  7. Php Rediret Script(12)
  8. Download Script For Mp3 Files(0)
  9. How Do I Connect To Live Database With Php Script?(6)
  10. Need Help Installing Dolphin Community Script!(5)
  11. Guessing Php Script(0)
  12. How To Make A View New Post Script?(5)
  13. Php Guest Online Script(2)


 



- Lo-Fi Version Time is now: 27th July 2008 - 01:17 AM