我想知道如何从ips的mysql数据库表中阻止给定ips的列表。 例如,我有一个注册表单,如果用户有一个不同于mysql dbs的ip,他应该看到该表单,否则他应该在该页面上看到一条消息“你不允许在这个网站上使用VPN / Proxy ips ”。 首先我如何创建mysql表和列,我需要添加哪些属性,所以我可以从csv文件导入ips。
MYSQL
CREATE TABLE IF NOT EXISTS 'blocked_ips'.......
并且不知道如何继续。尝试在phpmyadmin中使用VARCHAR(15)添加一个列,并在尝试导入ips的csv文件后,但它不起作用,它只导入2行并且只有00包含在2行中
<?php
//check for user ip
$ip = $_SERVER['REMOTE_ADDR'];
compare the ip got from the user with the mysql table column with ips
if the $ip matches with one from the table echo a message on the same page, (no pop-up).
else {
will echo the form below
?>
<DOCTYPE html!>
<head>
<title> Registration</title>
meta
meta
</head>
<body>
<table class="colortext" width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="30%"> </td>
<td height="20" width="70%">{advertiser_msg:8921}</td>
</tr>
<tr>
<td>{advertiser_msg:1092} <span class="mandatory">*</span></td>
<td>{USERFIELD}<span id="fg" style="display: none;white-space: nowrap;"></td>
</tr>
</form>
</body>
</html>
我这是一个菜鸟请帮忙。
答案 0 :(得分:1)
mysql_select_db("your database name") or die(mysql_error());
# Full Text Attempt
$query = mysql_query("SELECT `IP` FROM `your table` WHERE `IP` = '$ip'");
or
$query = mysql_query("SELECT `IP` FROM `database` WHERE `IP` LIKE '%$ip%'");
//chk for banned ip ipaddress
if (mysql_num_rows($query) > 0)
{
echo "<p> You are not allowed to register with proxy VPN </p>";
}
?>