php mysql ip_使用php和mysql有效禁止IP?
CREATE TABLE `banned_ip` (
`id` INT( 25 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`ip` VARCHAR( 25 ) NOT NULL ,
`reason` TEXT NOT NULL )config.php文件
// config
$config['host'] = "localhost"; // host name of your mysql server
$config['user'] = "username"; // your mysql username
$config['pass'] = "password"; // your mysql password
$config['db'] = "database"; // the database your table is in.
// the @ sign is an error supressor, meaning we can use our own error messages, this connects and selects db
@mysql_connect("$config[host]","$config[user]","$config[pass]")
or die("There was an error connecting to the database, MySql said:
".mysql_error()."");
@mysql_select_db("$config[db]")
or die("There was an error connecting to the database, MySql said:
".mysql_error()."");
?>Ban.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!");
else {
echo "Your Were not Banned";
$sql = "INSERT INTO user(ip) VALUES('$ip')";
}
?>我正在做的是檢查我的數據庫的IP,如果它被禁止或不。如果沒有被禁止,向他顯示消息“你沒有被禁止”并禁止他。
將他的IP存儲在數據庫中。然后,如果他再次來到現場,將會顯示“你被禁止從這個網站!”
通過這我給每個ip只有一次訪問我的內容。這個劇本足夠嗎?這個腳本不適合我。這不是禁止我的IP,而是一直向我展示我的內容。
總結
以上是生活随笔為你收集整理的php mysql ip_使用php和mysql有效禁止IP?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html canvas保存为图片,在HT
- 下一篇: python3ddos攻击_DDOS攻击