FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


IP Banning...





[FuN]goku
i need help to store ip bans in a .txt file.... or sql databas... i tried to make my own but wasnt successful... the only ones ive found where you ban them in the .php with an array.. but i want it in a .txt file and a form to add an ip to the file as well... so if u can help it would be much appreciated
Scorpio
using .htaccess is a good idea to do that..
http://www.javascriptkit.com/howto/htaccess5.shtml
[FuN]goku
mmm... yes that is good but... i still want php with .txt or mysql if possible just cuz i dont know much about .htaccess thanks tho Smile
yjwong
You could use the mysql_fetch_array() to fetch and array from the MySQL database or use file() to read a file into an array:

Code:

$banlist = file("banlist.txt");

foreach($banlist as $ips) {
    if($_SERVER["REMOTE_ADDR"] == $ips) {
        echo "Your IP is banned!";
        exit;
    }
}
[FuN]goku
yjwong wrote:
You could use the mysql_fetch_array() to fetch and array from the MySQL database or use file() to read a file into an array:

Code:

$banlist = file("banlist.txt");

foreach($banlist as $ips) {
    if($_SERVER["REMOTE_ADDR"] == $ips) {
        echo "Your IP is banned!";
        exit;
    }
}
hmm looks good....... but is there a way i can make a form to add an ip to the list... the ips would have to be on seperate lines yes??
Scorpio
There is nothing much to be known about htaccess if you just had taken some time to read the page I linked you to..

It contains details about how to create and modify .htaccess files

It is after all a simple text file..

where you add the content just like to a normal text file

You can just add the IPs manually and easily..

But if you are comfortable with mysql and php stuff, go right ahead..

I was merely implying that it is easy for even a beginner like me.
[FuN]goku
scorpio wrote:

You can just add the IPs manually and easily..
*sigh* the reason i want it to be php/mysql or putting the ip's in a text file... is because im making an admin control panel on my site... therefore im going to have admins and im not allowing them access to my webspace... so i need an ip ban script with something that will add the ips to the .txt line by line.


EDIT: Actually i might be able to work something out from this code
Code:
$banlist = file("banlist.txt");

foreach($banlist as $ips) {
    if($_SERVER["REMOTE_ADDR"] == $ips) {
        echo "Your IP is banned!";
        exit;
    }
}
ranzon
i would used this code to check ip..
Code:
<?php
$banlist = file("banlist.txt");
 
foreach($banlist as $ips) {
    if($_SERVER["REMOTE_ADDR"] == $ips) {
        die("Your IP is banned!");
    }
}
?>


And make a file for example called form.php:
Code:
 <form action="addban.php" method="post">
<input type="text" name="ip" size="40" />
<input type="submit" value="Add ip to banlist">
</form>


then you make a file called addban.php:
Code:
<?php
$iptoban = $_POST['ip'];

      if (!empty($iptoban))
{

   $fh = fopen("banlist.txt", "a");
      fwrite($fh, "".$iptoban."\n");
   fclose($fh);
}
else {
echo "you have to fill in an ip";
}

?>
[FuN]goku
ahhh thanks... now my admin panel is almost complete Twisted Evil thanks much
Related topics
Too much spam
PHP IP Ban
How can I...
News management system...
Ip Banning Using Php
Just curious..
cpanel help
IP Banning
News Script
Uploader v6,Shoutbox,Simple Gallery,Simple Directory indexer
News system
Block Proxy's
Chat box
.: User login systems for your site :. CHEAP AND EASY!
This topic is locked: you cannot edit posts or make replies.    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.