English 中文(简体)
如何仅从使用PHP的指定IP获得网站
原标题:How to access a website only from a specified IP using PHP
  • 时间:2010-07-20 06:07:06
  •  标签:
  • php

我只需要从专门的IP地址进入一个网站。

是否可能使用购买力平价。

这个项目正在开发之中,一些人利用了该项目,说“网站并不好”。 So

避免此类事情。 因此,我需要这样作。

最佳回答

尝试:

if ($_SERVER[ REMOTE_ADDR ] == "x.x.x.x") 
   echo "admin";

else 
   echo "user";

它检查用户,并采取行动。

问题回答

我建议使用“htaccess”文档,而不是在你的“php”编码中添加:

RewriteEngine On
RewriteBase   /
# IPs that are still allowed to view everything
RewriteCond %{REMOTE_ADDR} !^213.123.39.12$ [NC]
RewriteRule !^(noentry_image.jpg|favicon.ico)$ sorry_stay_out.html [L]

仅将“htaccess”档案放在你网站的根基。 然后,每个人都会被转往Sorry_stay_out.html网页,其中载有不露面的_。

获准访问的IP所有来访者都将认为该网址是正常的。 您可以重复“RewriteCond %{REMOTE_ADDR} !^213.123.39.12美元”这一行文,并按您的意愿,用不同的知识产权添加更多的知识产权。

仅作封锁的替代办法:

order allow,deny
allow from 62.57.16.192
allow from 72.232.56.154
deny from all

如果来源来自IP,你可以使用“SERVER”变量进行核对。 这里是一些有用的功能信标(仅为_SERVER):

function gethostname($ip){
return gethostbyaddr($ip);}

function gethostnamepretty($ip){
$host=gethostbyaddr($ip);
$host=explode( . ,$host);
$max=count($host);
return $host[$max - 2];}

function getRawRealIP($s){
if (!empty($s[ HTTP_CLIENT_IP ]))   //check ip from share internet
{
  $ip=$s[ HTTP_CLIENT_IP ];
}
elseif (!empty($s[ HTTP_X_FORWARDED_FOR ]))   //to check ip is pass from proxy
{
  $ip=$s[ HTTP_X_FORWARDED_FOR ];
}
else
{
  $ip=$s[ REMOTE_ADDR ];
}
return $ip;}

function checkIP($ip){
return long2ip(ip2long($ip));}

function useragent($s){
return $s[ HTTP_USER_AGENT ];}




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签