Banning IP Addresses - php Form

Author Topic: Banning IP Addresses  (Read 1292 times)

Offline alex

  • Global Moderator
  • *****
  • Posts: 77
  • Karma: +19/-0
    • View Profile
Banning IP Addresses
« on: February 16, 2010, 08:46:09 AM »


install.php
Code: [Select]
<?php
//make a MySQL connection
include('config.php');
//create a MySQL table in the selected database
mysql_query("CREATE TABLE `page` (
  `ipid` int(11) NOT NULL auto_increment,
  `ip` varchar(20) NOT NULL,
  `text` text collate utf8_unicode_ci,
   PRIMARY KEY  (`ipid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 
COLLATE=utf8_unicode_ci AUTO_INCREMENT=1"
)
or die(
mysql_error());
?>


config.php
Code: [Select]
<?php 
//MySQL Configuration
//DB Host (Normally 'localhost')
$dbhost 'localhost';
//DB Database Username
$dbusername 'root';
//DB Database User Password
$dbpassword 'mypassword';
//DB Database Name
$dbname 'dbname';
//mysql_connect function
$conn=mysql_connect($dbhost$dbusername$dbpassword);
if(!
$conn) :
   die(
'Could not connect: ' mysql_error());
endif;
$db=mysql_select_db($dbname$conn);
if(!
$db) :
   die (
'Cant connect to database : ' mysql_error());
endif;
?>


insert.php
Code: [Select]
<title>Insert Page</title>
<center><h2>INSERT PAGE</h2></center><BR>
<?php
//make a MySQL connection
include('config.php');
//to check if a submit button was clicked, use this...
if(isset($_POST['submit']))
{
$text $_POST['text'];
$ip $_POST['ip'];
//the INSERT INTO statement is used 
//to add new records to a database table
mysql_query("INSERT INTO page (text,ip)
VALUES ('$text','$ip')"
)
or die(
mysql_error());  
}else{
$ip $_SERVER['REMOTE_ADDR'];
echo 
"My IP = " $ip "<br>";
?>

<form method="post" action="insert.php">
<TABLE><TR><TD>
Text:
</TD>
<TD>
<input name="text" value="Sorry Guest, you are banned from using this website!" size="60" maxlength="255">
</TD></TR>
<TR><TD>
IP:
</TD>
<TD>
<input name="ip" size="60" maxlength="255">
</TD></TR>
<TR><TD>
<input type="submit" name="submit" value="submit">
</TD></TR></TABLE>
</form>
<?php
}
?>


webpage.php

Code: [Select]
<?php
////make a MySQL connection
include('config.php');
//get ip
$ip $_SERVER['REMOTE_ADDR'];
//get ip, text, linkurl from the page table
//..or..*=select everything from the table page
$result mysql_query("SELECT ip, text
FROM page"
)
or die(
mysql_error()); 
while(
$myrow mysql_fetch_assoc($result))
             {
if(
$myrow['ip']==$ip){
echo 
"<center><h2>$myrow[text]</h2></center>";
die();
}
}
?>

Web Page Code
:D :D