当前位置:首页 » 编程语言 » proxyphp

proxyphp

发布时间: 2023-08-24 19:12:07

php怎么禁止代理访问

要禁止代理访问,首先你要分辨对方是否使用了代理。
一般来说可以直接通过HTTP协议头中的REMOTE_ADDR、HTTP_VIA、HTTP_X_FORWARDED_FOR来判断。
比如,没有使用代理的情况下,后两个一般是空的,第一个为真实IP;
而使用了一般的代理的话,前两个会变成代理的IP,而第三个则是真实IP。
如果使用了一般的匿名代理的话,则三个都会变为代理的IP。
如果使用了欺骗型的匿名代理的话,前两个还是代理的IP,而第三个会被伪造为一个随机的IP。
如果使用了高级匿名代理的话,后两个和没有代理一样,是空的,第一个则为代理IP。
以上,由于HTTP协议头是很容易伪造的,一般很难判断用户是否使用了代理的,因为现在绝大多数人都是用的匿名代理,而一般要真的通过上面的方式能检测到的,很可能是只能通过代理访问网络的人,比如局域网之类。
不过如果你会JS的话,可以参考一下WebRTC,这个是HTML5带的一个API,可以直接获取到真实IP,然后发送回服务器,再和REMOTE_ADDR比对一下,就可以准确知道是否使用了代理了(使用了代理,那WebRTC获取到的肯定是和REMOTE_ADDR不一样的)。但是这个办法也仅限于使用了新版浏览器的用户(必须支持WebRTC),并且没有装屏蔽WebRTC的插件(可以通过Chrome的插件来禁用WebRTC的,较旧的浏览器也可以在配置里停用WebRTC),并且,也不是完全不可以伪造,因为随便写个脚本放在浏览器里替换掉默认的WebRTC API,就可以提供一个虚假的IP(不过就目前来看还没人这么干,大多数都是想办法直接停用WebRTC),所以这个办法也不是100%可靠的。
如果你可以准确判断代理了,就简单了,直接在代码里面die;掉就行了。

Ⅱ 为什么我php 用curl_proxy 不生效

这个是PHP的curl的代理模滚毕式,这个模式你在使用的时候是需要配合其他的一起使用的仔雀。所以单纯说这个没有用还要念备早看你其他的代码怎么写。
希望你可以把代码放上来看看。

Ⅲ 使用thinkphp 怎么实现反向代理

改自PHP Reverse Proxy PRP,修改了原版中的一些错误,支持了文件上传以及上传文件类型识别,支持指定IP,自适应SAE环境。
使用方法
?123456789 <?php $proxy=new PhpReverseProxy(); $proxy->port="8080"; $proxy->host="ww"; //$proxy->ip="1.1.1.1"; $proxy->forward_path=""; $proxy->connect(); $proxy->output(); ?>
源代码
<?php //Source Code: http //www xiumu.org/technology/php-reverse-proxy-class.shtml class PhpReverseProxy{ public $publicBaseURL; public $outsideHeaders; public $XRequestedWith; public $sendPost; public $port,$host,$ip,$content,$forward_path,$content_type,$user_agent, $XFF,$request_method,$IMS,$cacheTime,$cookie,$authorization; private $http_code,$lastModified,$version,$resultHeader; const chunkSize = 10000; function __construct(){ $this->version="PHP Reverse Proxy (PRP) 1.0"; $this->port="8080"; $this->host="127.0.0.1"; $this->ip=""; $this->content=""; $this->forward_path=""; $this->path=""; $this->content_type=""; $this->user_agent=""; $this->http_code=""; $this->XFF=""; $this->request_method="GET"; $this->IMS=false; $this->cacheTime=72000; $this->lastModified=gmdate("D, d M Y H:i:s",time()-72000)." GMT"; $this->cookie=""; $this->XRequestedWith = ""; $this->authorization = ""; } function translateURL($serverName) { $this->path=$this->forward_path.$_SERVER['REQUEST_URI']; if(IS_SAE) return $this->translateServer($serverName).$this->path; if($_SERVER['QUERY_STRING']=="") return $this->translateServer($serverName).$this->path; else return $this->translateServer($serverName).$this->path."?".$_SERVER['QUERY_STRING']; } function translateServer($serverName) { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = $this->left(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; if($this->port=="") return $protocol."://".$serverName; else return $protocol."://".$serverName.":".$this->port; } function left($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); } function preConnect(){ $this->user_agent=$_SERVER['HTTP_USER_AGENT']; $this->request_method=$_SERVER['REQUEST_METHOD']; $tempCookie=""; foreach ($_COOKIE as $i => $value) { $tempCookie=$tempCookie." $i=$_COOKIE[$i];"; } $this->cookie=$tempCookie; if(empty($_SERVER['HTTP_X_FORWARDED_FOR'])){ $this->XFF=$_SERVER['REMOTE_ADDR']; } else { $this->XFF=$_SERVER['HTTP_X_FORWARDED_FOR'].", ".$_SERVER['REMOTE_ADDR']; } } function connect(){ if(empty($_SERVER['HTTP_IF_MODIFIED_SINCE'])){ $this->preConnect(); $ch=curl_init(); if($this->request_method=="POST"){ curl_setopt($ch, CURLOPT_POST,1); $postData = array(); $filePost = false; $uploadPath = 'uploads/'; if (IS_SAE) $uploadPath = SAE_TMP_PATH; if(count($_FILES)>0){ if(!is_writable($uploadPath)){ die('You cannot upload to the specified directory, please CHMOD it to 777.'); } foreach($_FILES as $key => $fileArray){ ($fileArray["tmp_name"], $uploadPath . $fileArray["name"]); $proxyLocation = "@" . $uploadPath . $fileArray["name"] . ";type=" . $fileArray["type"]; $postData = array($key => $proxyLocation); $filePost = true; } } foreach($_POST as $key => $value){ if(!is_array($value)){ $postData[$key] = $value; } else{ $postData[$key] = serialize($value); } } if(!$filePost){ //$postData = http_build_query($postData); $postString = ""; $firstLoop = true; foreach($postData as $key => $value){ $parameterItem = urlencode($key)."=".urlencode($value); if($firstLoop){ $postString .= $parameterItem; } else{ $postString .= "&".$parameterItem; } $firstLoop = false; } $postData = $postString; } //echo print_r($postData); //curl_setopt($ch, CURLOPT_VERBOSE, 0); //curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)"); $this->sendPost = $postData; //var_mp(file_exists(str_replace('@','',$postData['imgfile'])));exit; curl_setopt($ch, CURLOPT_POSTFIELDS,$postData); //curl_setopt($ch, CURLOPT_POSTFIELDS,file_get_contents($proxyLocation)); //curl_setopt($ch, CURLOPT_POSTFIELDS,file_get_contents("php://input")); } //gets rid of mulitple ? in URL $translateURL = $this->translateURL(($this->ip)?$this->ip:$this->host); if(substr_count($translateURL, "?")>1){ $firstPos = strpos($translateURL, "?", 0); $secondPos = strpos($translateURL, "?", $firstPos + 1); $translateURL = substr($translateURL, 0, $secondPos); } curl_setopt($ch,CURLOPT_URL,$translateURL); $proxyHeaders = array( "X-Forwarded-For: ".$this->XFF, "User-Agent: ".$this->user_agent, "Host: ".$this->host ); if(strlen($this->XRequestedWith)>1){ $proxyHeaders[] = "X-Requested-With: ".$this->XRequestedWith; //echo print_r($proxyHeaders); } curl_setopt($ch,CURLOPT_HTTPHEADER, $proxyHeaders); if($this->cookie!=""){ curl_setopt($ch,CURLOPT_COOKIE,$this->cookie); } curl_setopt($ch,CURLOPT_FOLLOWLOCATION,false); curl_setopt($ch,CURLOPT_AUTOREFERER,true); curl_setopt($ch,CURLOPT_HEADER,true); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); $output=curl_exec($ch); $info = curl_getinfo( $ch ); curl_close($ch); $this->postConnect($info,$output); }else { $this->lastModified=$_SERVER['HTTP_IF_MODIFIED_SINCE']; $this->IMS=true; } } function postConnect($info,$output){ $this->content_type=$info["content_type"]; $this->http_code=$info['http_code']; //var_mp($info);exit; if(!empty($info['last_modified'])){ $this->lastModified=$info['last_modified']; } $this->resultHeader=substr($output,0,$info['header_size']); $content = substr($output,$info['header_size']); if($this->http_code=='200'){ $this->content=$content; }elseif( ($this->http_code=='302' || $this->http_code=='301') && isset($info['redirect_url'])){ $redirect_url = str_replace($this->host,$_SERVER['HTTP_HOST'],$info['redirect_url']); if (IS_SAE) $redirect_url = str_replace('http://fetchurl.sae.sina.com.cn/','',$info['redirect_url']); header("Location: $redirect_url"); exit; }elseif($this->http_code=='404'){ header("HTTP/1.1 404 Not Found"); exit("HTTP/1.1 404 Not Found"); }elseif($this->http_code=='500'){ header('HTTP/1.1 500 Internal Server Error'); exit("HTTP/1.1 500 Internal Server Error"); }else{ exit("HTTP/1.1 ".$this->http_code." Internal Server Error"); } } function output(){ $currentTimeString=gmdate("D, d M Y H:i:s",time()); $expiredTime=gmdate("D, d M Y H:i:s",(time()+$this->cacheTime)); $doOriginalHeaders = true; if($doOriginalHeaders){ if($this->IMS){ header("HTTP/1.1 304 Not Modified"); header("Date: Wed, $currentTimeString GMT"); header("Last-Modified: $this->lastModified"); header("Server: $this->version"); }else{ header("HTTP/1.1 200 OK"); header("Date: Wed, $currentTimeString GMT"); header("Content-Type: ".$this->content_type); header("Last-Modified: $this->lastModified"); header("Cache-Control: max-age=$this->cacheTime"); header("Expires: $expiredTime GMT"); header("Server: $this->version"); preg_match("/Set-Cookie:[^\n]*/i",$this->resultHeader,$result); foreach($result as $i=>$value){ header($result[$i]); } preg_match("/Content-Encoding:[^\n]*/i",$this->resultHeader,$result); foreach($result as $i=>$value){ //header($result[$i]); } preg_match("/Transfer-Encoding:[^\n]*/i",$this->resultHeader,$result); foreach($result as $i=>$value){ //header($result[$i]); } echo($this->content); /* if(stristr($this->content, "error")){ echo print_r($this->sendPost); } */ } } else{ $headerString = $this->resultHeader; //string $headerArray = explode("\n", $headerString); foreach($headerArray as $privHeader){ header($privHeader); } if(stristr($headerString, "Transfer-encoding: chunked")){ flush(); ob_flush(); $i = 0; $maxLen = strlen($this->content); while($i < $maxLen){ $endChar = $i + self::chunkSize; if($endChar >= $maxLen){ $endChar = $maxLen - 1; } $chunk = substr($this->content, $i, $endChar); $this->mp_chunk($chunk); flush(); ob_flush(); $i = $i + $endChar; } } else{ echo($this->content); } //echo "header: ".print_r($headerArray); //header($this->resultHeader); } } function mp_chunk($chunk) { echo sprintf("%x\r\n", strlen($chunk)); echo $chunk; echo "\r\n"; } function getOutsideHeaders(){ $headers = array(); foreach ($_SERVER as $name => $value){ if (substr($name, 0, 5) == 'HTTP_') { $name = str_replace(' ', '-', ucwords(strtolower(str_replace('_', ' ', substr($name, 5))))); $headers[$name] = $value; }elseif ($name == "CONTENT_TYPE") { $headers["Content-Type"] = $value; }elseif ($name == "CONTENT_LENGTH") { $headers["Content-Length"] = $value; }elseif(stristr($name, "X-Requested-With")) { $headers["X-Requested-With"] = $value; $this->XRequestedWith = $value; } } //echo print_r($headers); $this->outsideHeaders = $headers; return $headers; } } ?>

Ⅳ PHP实现代理IP

“代理IP”现在有很多种的,就是软件改IP的。
软件上有很多IP点提供给使用者切换的
在电脑上安装IP转换器,
在IP软件上选择不同的IP点连接就可以了的。
推荐软件。可找到类似软件的。
全国大多数城市(数百万IP点任意切换)
希望可以帮到你。多少电脑多可以使用的。

Ⅳ mysql 如何实现读写分离,用mysql-proxy 或者直接用php连接两个数据库

Mysql主从配置,实现读写分离
原理:主服务器(Master)负责网站NonQuery操作,从服务器负责Query操作,用户可以根据网站功能模特性块固定访问Slave服务器,或者自己写个池或队列,自由为请求分配从服务器连接。主从服务器利用MySQL的二进制日志文件,实现数据同步。二进制日志由主服务器产生,从服务器响应获取同步数据库。
具体实现:
1、在主从服务器上都装上MySQL数据库,windows系统鄙人安装的是mysql_5.5.25.msi版本,Ubuntu安装的是mysql-5.6.22-linux-glibc2.5-i686.tar
windows安装mysql就不谈了,一般地球人都应该会。鄙人稍微说一下Ubuntu的MySQL安装,我建议不要在线下载安装,还是离线安装的好。大家可以参考 http://www.linuxidc.com/Linux/2013-01/78716.htm 这位不知道大哥还是姐妹,写的挺好按照这个就能装上。在安装的时候可能会出现几种现象,大家可以参考解决一下:
(1)如果您不是使用root用户登录,建议 su - root 切换到Root用户安装,那就不用老是 sudo 了。
(2)存放解压的mysql 文件夹,文件夹名字最好改成mysql
(3)在./support-files/mysql.server start 启动MySQL的时候,可能会出现一个警告,中文意思是启动服务运行读文件时,忽略了my.cnf文件,那是因为my.cnf的文件权限有问题,mysql会认为该文件有危险不会执行。但是mysql还会启动成功,但如果下面配置从服务器参数修改my.cnf文件的时候,你会发现文件改过了,但是重启服务时,修改过后的配置没有执行,而且您 list一下mysql的文件夹下会发现很多.my.cnf.swp等中间文件。这都是因为MySQL启动时没有读取my.cnf的原因。这时只要将my.cnf的文件权限改成my_new.cnf的权限一样就Ok,命令:chmod 644 my.cnf就Ok
(4)Ubuntu中修改文档内容没有Vim,最好把Vim 装上,apt-get install vim,不然估计会抓狂。
这时候我相信MySQL应该安装上去了。
2、配置Master主服务器
(1)在Master MySQL上创建一个用户‘repl’,并允许其他Slave服务器可以通过远程访问Master,通过该用户读取二进制日志,实现数据同步。

Ⅵ 怎么样用php语言实现通过proxy代理服务器访问网站呢

function curl_string ($url,$timeout = 3,$proxy=1){
$ua = array('Mozilla','Opera','Microsoft Internet Explorer','ia_archiver');
$op = array('Windows','Windows XP','Linux','Windows NT','Windows 2000','OSX');
$agent = $ua[rand(0,3)].'/'.rand(1,8).'.'.rand(0,9).' ('.$op[rand(0,5)].' '.rand(1,7).'.'.rand(0,9).'; en-US;)';
Tor 地址与端口
$tor = 'http://www.aimilife.com'; //这里是你的代理服务器
连接超时设置
$timeout = 3;
$ack = curl_init();
if($proxy)
{
curl_setopt($ack, CURLOPT_PROXY, $tor);
}
curl_setopt($ack, CURLOPT_URL, $url);
curl_setopt($ack, CURLOPT_HEADER, 0);
curl_setopt($ack, CURLOPT_USERAGENT, $agent);
curl_setopt($ack, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ack, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ack, CURLOPT_TIMEOUT, $timeout);
$result = curl_exec($ack);
curl_close($ack);
return $result;

}

热点内容
海量照片存储 发布:2025-03-15 22:23:07 浏览:161
androidgif控件 发布:2025-03-15 22:10:51 浏览:338
我的世界手机版非常好玩的服务器推荐 发布:2025-03-15 22:04:48 浏览:178
怎样解压手机文件 发布:2025-03-15 22:04:47 浏览:525
我的世界手机基岩版怎么做服务器 发布:2025-03-15 22:04:11 浏览:100
邮件发送压缩文件 发布:2025-03-15 22:04:06 浏览:820
数据库中的数据特征 发布:2025-03-15 21:56:20 浏览:29
账号密码可以用什么替换 发布:2025-03-15 21:55:43 浏览:699
主板自带什么配置好 发布:2025-03-15 21:49:57 浏览:699
交换空间linux 发布:2025-03-15 21:49:57 浏览:85