Lost Password?

Go Back   CodeCall Programming Forum > Software Development > Tutorials > PHP Tutorials

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

PHP Tutorials PHP Tutorials

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-15-2007, 02:13 PM
Jaan's Avatar   
Jaan Jaan is offline
<img src="http://forum.codecall.net/images/userbar/mod.png" alt="Mod">
 
Join Date: Dec 2006
Location: Estonia
Age: 17
Posts: 890
Last Blog:
Wadio Media Layout Com...
Credits: 56
Rep Power: 15
Jaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the roughJaan is a jewel in the rough
Send a message via MSN to Jaan
Default Ban IPs using MySQL

Oki it's simple..

First you must make a tables into your database:

tables.sql:

PHP Code:
CREATE TABLE `banned_ip` (
`
idINT25 NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`
ipVARCHAR25 NOT NULL ,
`
reasonTEXT NOT NULL

connect.php

PHP Code:
$con mysql_connect("localhost""test""test");
if(!
$con){
die(
"Can not connect to database: ".mysql_error());
}
$db mysql_select_db("test"$con);
if(!
$db){
die(
"Can not select database: ".mysql_error());

Now admin panel

admin.php

PHP Code:
<?php
include("connect.php");

//This function will display the banning form
function ban(){

echo 
"<form action='?act=ban' method='post'>"
    
."<table width='500' border='1'>
    <tr>
    <td><center><font size='+2'>Ban!</font></center></td>
    </tr>
    <tr>
    <td>IP:<br> <input type='text' name='ip' size='30' /><br />
    Reason:<br />
    <textarea rows='10' cols='55' name='reason'></textarea><br>
    <input type='submit' value='Ban!'>
    </td>
    </tr>
    </table>"
;
    
echo 
"<br><br>";

//Let's connect to database and choose the database
$result mysql_query("SELECT * FROM banned_ip");
$rows mysql_num_rows($result);
if(
$rows 0){

//Display banned IPs 
echo "<table width='700' border='1'>
    <tr>
    <td><center><font size='+2'>Banned IPs</font></center></td>
    </tr>
    <tr>
    <td>"
;
        echo 
"<table border='1' width='100%'>"
            
."<tr>"
            
."<td width='25%'><b>Id</b></td><td width='25%'><b>Ip</b></td><td width='25%'><b>Reason</b></td><td width='25%'><b>Action</b></td>"
            
."</tr>";

while(
$row mysql_fetch_array($result)){
echo 
"<tr><td width='25%'>".$row['id']."</td><td width='25%'>".$row['ip']."</td><td width='25%'>".$row['reason']."</td><td width='25%'><a href='?act=del&id=".$row['id']."'>Delete</a></td></tr>";
}

    echo 
"</table>";
    
echo 
"</td>
    </tr>
    </table>"
;
}
}

//This function will ban a IP
function ban_ip(){

$ip $_REQUEST['ip'];
$reason $_REQUEST['reason'];

//If there are errors display them in here
if(empty($ip)){
die(
"Please insert a IP!");
}

if(empty(
$reason)){
die(
"Please insert a reason!");
}

//Let's insert this ip and reason into your database

$insert mysql_query("INSERT INTO banned_ip (ip, reason) VALUES ('$ip', '$reason')");

//If there was problems with inserting those things into database, lets display the error
if(!$insert){
die(
mysql_error());
}

echo 
"<table width='500' border='1'>"
    
."<tr>"
    
."<td><center>Info</center></td>"
    
."</tr>"
    
."<tr>"
    
."<td><br>IP: <b>$ip</b> was banned, Reason: <b>$reason</b><br><a href='admin.php'>Back</a><br></td>"
    
."</tr>"
    
."</table>";
}

//This function will delete banned ip

function del(){

$id $_GET['id'];

$del mysql_query("DELETE FROM banned_ip WHERE id='$id'");

//If there's problem with deleting then display an error
if(!$del){
die(
mysql_error());
}

echo 
"<table width='500' border='1'>"
    
."<tr>"
    
."<td><center>Info</center></td>"
    
."</tr>"
    
."<tr>"
    
."<td><br>Ban deleted, <a href='admin.php'>Go back</a><br></td>"
    
."</tr>"
    
."</table>";

}

switch(
$act){

default;
ban();
break;

case 
"ban";
ban_ip();
break;

case 
"del";
del();
break;

}

?>
Well now make another file called

bans.php
PHP Code:
<?php
include("connect.php");
$ip $_SERVER['REMOTE_ADDR'];
$find_ip mysql_query("SELECT * FROM banned_ip WHERE ip='$ip'");
$ban mysql_fetch_array($find_ip);
if(
$ip == $ban['ip']){ die("You are banned from this site!");}
?>
just add this code to your files and your stuff is protected:

PHP Code:
<?php
include("bans.php");
?>
and your files are protected..

have fun!

Updated!!
__________________


Cheap & Professional Web Design | Need help? Send a PM

Last edited by Jaan; 02-07-2007 at 05:34 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
MYSQL CheatSheet - A must for MySQL Users reachpradeep Database & Database Programming 1 03-03-2007 03:05 PM
Simple MySQL Database Search Jaan PHP Tutorials 1 01-01-2007 10:15 AM
Shell: MySQL Database Backup Jordan Tutorials 0 08-15-2006 03:18 PM
How do I make a Mysql Database Connection Chan PHP Forum 1 07-17-2006 11:00 AM
MySQL Resources dirkfirst Database & Database Programming 1 05-25-2006 02:31 AM


All times are GMT -5. The time now is 01:49 AM.

Contest Stats

Xav ........ 1322.18
MeTh0Dz|Reb0rn ........ 1053.7
morefood2001 ........ 879.43
John ........ 877.37
marwex89 ........ 869.98
WingedPanther ........ 830.24
Brandon W ........ 735.07
chili5 ........ 309.39
Steve.L ........ 239.84
dcs ........ 216.02

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 82%

Ads