|
发表于 2007-5-14 08:21:58
|
显示全部楼层
取得客户端的IP,$_SERVER["REMOTE_ADDR"]
IP不在范围不给访问。
答2:
限制某个页面,用楼上的方法.
if(eregi("^192.168.0.",$_SERVER['REMOTE_ADDR'])){
echo "可以访问";
} else {
echo "拒绝访问";
}
----------------
限制整个网站(apache服务器)在httpd.conf中:
deny from all
allow from 192.168.0.x
答3:
if(eregi("^192.168.0.",$_SERVER['REMOTE_ADDR'])){
===>if(eregi("^192\.168\.0\.",$_SERVER['REMOTE_ADDR'])){
答4:
function getip()
{
if(getenv('HTTP_CLIENT_IP'))
{
$onlineip = getenv('HTTP_CLIENT_IP');
}
elseif(getenv('HTTP_X_FORWARDED_FOR'))
{
$onlineip = getenv('HTTP_X_FORWARDED_FOR');
}
elseif(getenv('REMOTE_ADDR'))
{
$onlineip = getenv('REMOTE_ADDR');
}
else
{
$onlineip = $HTTP_SERVER_VARS['REMOTE_ADDR'];
}
return $onlineip;
}
function estop($ips)
{
global $db;
$ip = explode('.',$ips);
$sql = "select * from ipestop";
$db->query($sql);
while ($banned = $db->records())
{
$exists = 0;
for($i = 1; $i <= 4; $i++)
{
if($banned["ip$i"] == -1)
{
$exists++;
}
elseif($banned["ip$i"] == $ip[$i-1])
{
$exists++;
}
}
if($exists == 4)
{
die("该IP 已经被禁止访问!");
}
}
}
表结构:
CREATE TABLE ipestop(
id smallint(6) unsigned NOT NULL auto_increment,
ip1 smallint(3) NOT NULL default '0',
ip2 smallint(3) NOT NULL default '0',
ip3 smallint(3) NOT NULL default '0',
ip4 smallint(3) NOT NULL default '0',
PRIMARY KEY (id),
KEY ip1 (ip1),
KEY ip2 (ip2),
KEY ip3 (ip3),
KEY ip4 (ip1)
) TYPE=MyISAM; |
|