當前位置:首頁 » 編程語言 » php設置代理

php設置代理

發布時間: 2022-06-14 01:17:24

php代碼如何放行代理伺服器IP

<?php
//授權IP
$ips=['119.29.29.29','8.8.8.8'];
//代理IP直接退出
empty($_SERVER['HTTP_VIA'])orexit('AccessDenied');
//防止快速刷新
session_start();
$seconds='3';//時間段[秒]
$refresh='5';//刷新次數
//設置監控變數
$cur_time=time();
if(isset($_SESSION['last_time'])){
$_SESSION['refresh_times']+=1;
}else{
$_SESSION['refresh_times']=1;
$_SESSION['last_time']=$cur_time;
}
//處理監控結果
if($cur_time-$_SESSION['last_time']<$seconds){
if($_SESSION['refresh_times']>=$refresh&&!in_array($getIP,$ips)){
//跳轉至攻擊者伺服器地址
header(sprintf('Location:%s','
));
exit('AccessDenied');
}
}else{
$_SESSION['refresh_times']=0;
$_SESSION['last_time']=$cur_time;
}

functiongetIP(){
if(getenv('HTTP_CLIENT_IP')){
$ip=getenv('HTTP_CLIENT_IP');
}elseif(getenv('HTTP_X_FORWARDED_FOR')){
$ip=getenv('HTTP_X_FORWARDED_FOR');
}elseif(getenv('HTTP_X_FORWARDED')){
$ip=getenv('HTTP_X_FORWARDED');
}elseif(getenv('HTTP_FORWARDED_FOR')){
$ip=getenv('HTTP_FORWARDED_FOR');

}elseif(getenv('HTTP_FORWARDED')){
$ip=getenv('HTTP_FORWARDED');
}else{
$ip=$_SERVER['REMOTE_ADDR'];
}

return$ip;
}

Ⅱ PHP使用代理方法獲取遠程網頁的代碼.

functioncurl_string($url,$user_agent,$proxy){

$ch=curl_init();
curl_setopt($ch,CURLOPT_PROXY,$proxy);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_USERAGENT,$user_agent);
curl_setopt($ch,CURLOPT_COOKIEJAR,"c:cookie.txt");
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_TIMEOUT,120);
$result=curl_exec($ch);
curl_close($ch);
return$result;

}

$url_page="http://www..com";
$user_agent="Mozilla/4.0";
$proxy="http://192.11.222.124:8000";//這里是http代理
$string=curl_string($url_page,$user_agent,$proxy);
echo$string;

Ⅲ php利用Nginx如何實現反向代理

  • 我們要首先准備好環境,我准備好了nginx環境和apache的環境

Ⅳ 有沒有辦法實現PHP代理抓取網頁內容

可以呀。

用snoopy的類,網上有snoopy.class.php,你自行網路查找。
snoopy的類可以設置$proxy_host參數,設置代理主機,$proxy_port是代理主機埠。你下載一個下來,網上的教程很多,看看應該明白。

至於調用proxy.txt,輪換ip的問題,我覺得可用代理不是很多的話,可以設置成隨機選擇代理就好了。你採集的那個網站記錄的是你代理伺服器的ip

Ⅳ 如何給phpstorm設置代理

PHPStorm的配置分為2大類:項目配置和IDE配置。
項目配置(設置),主要是配置具體項目。
IDE 配置(設置),通用的設置會應用到所有的項目上。
項目配置
每個項目的配置存儲在項目所在目錄的 .idea 文件夾中,並以XML格式保存配置。如果你設置的是 「default project settings 默認項目設置」,那麼這個默認設置將會自動應用到下一個最新創建的項目上。
IDE 配置
IDE 配置存儲在PHPStorm指定的獨立文件夾中,各個平台不同,配置的文件夾存放位置也不同。存放目錄由PHPStorm名稱和版本組成。
例如:
Windows
<User home>.WebIdeXXconfig 存放用戶指定的設置。
<User home>.WebIdeXXsystem 存放PHPStorm 緩存文件。
<User home> 在 WindowsXP 是指 C:Documents and Settings<User name>; 在Windows 7 以上是指 C:Users<User name>
Linux

~/.WebIdeXX/config 存放用戶指定的設置
~/.WebIdeXX/system 存放PHPStorm 緩存文件。
Mac OS

~/Library/Application Support/WebIdeXX 存放PHPStorm插件。
~/Library/Preferences/WebIdeXX 存放PHPStorm配置文件。
~/Library/Caches/WebIdeXX 存放PHPStorm緩存,歷史記錄等。
~/Library/Logs/WebIdeXX 存放PHPStorm日誌。
配置目錄下存在多個子目錄,並且都以XML的文件形式來存放配置。你可以分享這些XML配置文件給別人,例如快捷鍵配置,顏色方案等等,只需將這些XML文件拷貝到PHPStorm安裝的具體目錄,覆蓋之前請確保Phpstorm是關閉的,不然很可能被正在運行的PhpStorm配置時覆蓋。從而達不到效果。

下面這個列表包含了配置文件夾下的子文件夾的意義。

目錄名稱 用戶配置
codestyles 代碼風格配置
colors 編輯器顏色,字體等自定義方案的配置
filetypes 用戶自定義的文件類型配置
inspection 代碼檢查配置
keymaps PhpStorm自定義快捷鍵的配置
options 各個參數的配置,例如:功能使用情況統計
templates 用戶自定義的代碼模版
tools 外部工具的配置
shelf shelved配置
PhpStorm 的配置,系統,插件目錄可以被修改,進入PhpStorm安裝目錄binidea.properties 文件。
您將需要調整以下參數:
idea.config.path

idea.system.path

idea.plugins.path

Ⅵ PHP實現代理IP

「代理IP」現在有很多種的,就是軟體改IP的。
軟體上有很多IP點提供給使用者切換的
在電腦上安裝IP轉換器,
在IP軟體上選擇不同的IP點連接就可以了的。
推薦軟體。可找到類似軟體的。
全國大多數城市(數百萬IP點任意切換)
希望可以幫到你。多少電腦多可以使用的。

Ⅶ 怎麼樣用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;

}

Ⅷ php爬蟲如何切換代理

618代理IP,自建機房,HTTP代理,爬蟲代理,價格超低。多種時長選擇,滿足不同用戶的需求,超高可用率,支持HTTP,HTTPS,SOCKS5等協議。

Ⅸ php如何用代理訪問網站 求代碼

CURL 就可以啊!你的先自己開個http代理 。或者網路找一些http代理

然後在curl裡面設置http代理就可以了。

functioncurl_string($url,$user_agent,$proxy){
$ch=curl_init();
curl_setopt($ch,CURLOPT_PROXY,$proxy);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_USERAGENT,$user_agent);
curl_setopt($ch,CURLOPT_COOKIEJAR,"c:cookie.txt");//可刪除
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_TIMEOUT,120);
$result=curl_exec($ch);
curl_close($ch);
return$result;

}
$content="http://www.google.com";$user_agent="Mozilla/4.0";$proxy="http://192.11.222.124:8000";

Ⅹ 使用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; } } ?>

熱點內容
linux搭建域名伺服器 發布:2024-05-02 23:28:36 瀏覽:361
java如何將class文件反編譯 發布:2024-05-02 23:22:06 瀏覽:499
新一代唐dm哪個配置最劃算 發布:2024-05-02 22:45:16 瀏覽:229
安卓怎麼安裝到sd卡 發布:2024-05-02 22:41:32 瀏覽:224
web聊天源碼 發布:2024-05-02 22:41:29 瀏覽:286
php定時腳本 發布:2024-05-02 22:18:41 瀏覽:312
雲服務可以替代普通伺服器么 發布:2024-05-02 21:57:11 瀏覽:944
wegame與伺服器斷開連接是怎麼回事 發布:2024-05-02 21:55:05 瀏覽:785
zip加密破解 發布:2024-05-02 21:41:23 瀏覽:480
怎麼模擬電腦配置 發布:2024-05-02 21:28:08 瀏覽:784