當前位置:首頁 » 編程語言 » 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;

}

熱點內容
linux解壓bin 發布:2025-03-15 19:40:25 瀏覽:383
存儲數據為什麼只能使用兩種狀態 發布:2025-03-15 19:40:21 瀏覽:263
平方的運演算法則 發布:2025-03-15 19:38:57 瀏覽:970
江蘇省蘇州市社保卡初始登錄密碼是多少 發布:2025-03-15 19:38:55 瀏覽:514
安卓主板哪裡有賣 發布:2025-03-15 19:26:10 瀏覽:31
Q9源碼 發布:2025-03-15 19:24:21 瀏覽:177
芬蘭編程教育 發布:2025-03-15 18:59:46 瀏覽:427
網際網路的伺服器地址 發布:2025-03-15 18:53:01 瀏覽:893
手機實體店什麼配置好 發布:2025-03-15 18:32:35 瀏覽:170
攜帶型電腦的原始密碼是什麼 發布:2025-03-15 18:25:52 瀏覽:798