Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 627 Vote(s) - 3.43 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Banned IP Redirecting[PHP] and [mySQL]

#1
BANNED IP REDIRECTING CODE

Hello Hack Community...
The purpose of this code is to prevent users from visiting pages if their ip addresses are banned. Using this code, you can ban IP addresses from visiting your site. It can also be useful for preventing proxy users and VPN users from visiting your site.

I've got two codes, one in which the banned IP addresses are stored in a txt file named list.txt, and another code i which the banned IP addresses are stored in a database name mydb with a table named banned and column named ip.

1. Code in which the banned IP addresses are stored in list.txt file :
PHP Code:
<?php
//Code made by The Alchemist
$filename="list.txt";//All the banned IP addresses stored in this file
$ip=$_SERVER['REMOTE_ADDR']; // ip address of the user
$count=0;//setting a counter
if($file_exists($filename))
{
 
$file=fopen($filename,'r');//only reading contents of file
 
while(!feof($file)) //checking contents of file till the end
 
{
 
$reading=fgets($file); //checking contents of file line by line
 
if($ip==$reading//if IP of user matches with any among the list
 
{
 
$count=1;//setting the counter if value matches
 
break;
 }
 }
 
fclose($file);
}
if(
$count!=0)
{
 
header('Location : forbanned.php'); //redirecting to the page for banned members
}
else 
//Otherwise, show the original contents of the page
{
 echo 
'<html><title>Welcome></title><body><h1>Actual contents of page</h1></body></html>';
}
?>

Now, the page where the prestigious users with banned IP addresses are redirected(This is the forbanned.php thats redirected to in my codes) :
PHP Code:
<?php
//Code made by The Alchemist
//Welcome the prestigious banned ips with this page
echo '<html><title>For the banned</title><body><h1>You are banned from this site.</br>Get Lost!!</body></html>';
?>

Remember, the IP addresses should be stored in the list.txt file in this way :
Quote:127.0.0.1
127.0.0.2
127.0.0.3
127.0.0.4

2. Code in which the banned IP addresses are stored in a mySQL database :
PHP Code:
<?php
//Code made by The Alchemist
$ip=$_SERVER['REMOTE_ADDR'];//Finding IP address of user
$hostname='localhost';//assuming host is localhost
$user='admin';//assuming username to be admin
$password='password';//assuming password to be password
$dbname='mydb';//assuming database name to be mydb
$con=mysql_connect($hostname$user$password) or DIE('Connection to host failed');
mysql_select_db($dbname,$con) or DIE('Database name is not available!');
$query="SELECT * from banned where ip='$ip'";//table name is banned and column name is ip
$chk=mysql_query($query,$con);
$res=mysql_num_rows($chk);
if(
$res!=0//If the user's ip is among the ones banned listed in the database
{
 
header('Location : forbanned.php');//redirect to the page for banned members
}
else 
//Show actual contents if the user is not banned
{
 echo 
'<html><title>Welcome></title><body><h1>Actual contents of page</h1></body></html>';
}
?>

Thats it...
Enjoy..

[b]Please don't forget to give feedback!!
:cool:[/b]
Reply

#2
iNteresting for me , :smile: , thanks for the share
Reply

#3
Quote:(08-16-2012, 04:19 PM)bluedog.tar.gz Wrote:

[To see links please register here]

Good tutorial, may always come in use for everyone :] +1
Glad you liked it too... Thanks for the feedback..
Reply

#4
Quote:(08-16-2012, 04:09 PM)Shining White Wrote:

[To see links please register here]

iNteresting for me , :smile: , thanks for the share
Glad to see that you liked it... Thanks for the feedback...
This is just my second PHP script that I'm sharing in Hack Community... Please do point out mistakes if you see any in my codes...
Reply

#5
Good tutorial, may always come in use for everyone :] +1
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through