導航:首頁 > 編程語言 > php代理代碼

php代理代碼

發布時間:2022-07-06 06:08:39

php如何讓伺服器用代理下載文件

訪問PHP伺服器,但是從內網機器上獲取文件下載?
如果你內網那台機子有獨立IP的話,可以分配個子域名。
如果沒有獨立IP的話,試試埠映射。

Ⅱ php代理問題

你應該是資料庫管理的吧,必須有一個會員表吧,每個會員一條記錄,記錄每個會員的相關信息,大概有這些欄位:

會員表(會員ID,姓名,會員級別(1,2,3),上級會員ID,祖宗會員ID)


會員ID可以使用身份證號,也可以讓資料庫自己編碼,新增加會員需要做三件事情:

  1. 獲取上級會員的祖宗會員ID,

    SELECT 祖宗ID FROM 會員表 WHERE 會員ID='推薦人ID'

  2. 添加會員

    INSERT INTO 會員表 VALUES ('新會員ID','新會員姓名','新會員默認級別例如3','推薦人ID','祖宗ID')

  3. 修改推薦人的級別

    SELECT COUNT(*) FROM 會員表 WHERE 上級會員ID='推薦人ID'

    如果查詢的結果數量>=10,那麼執行下面的修改

    UPDATE 會員表 SET 會員級別=2 WHERE 會員ID='推薦人ID' AND會員級別=3

Ⅲ PHP代碼 ,或者原理,就是如何設置二級域名或者一級域名綁定成為代理, 或者是分站。

你可以參考一下相關的分類信息網站是如何實現的.操作原理就是通過設計

Ⅳ 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;

Ⅳ 使用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面試題】請寫出php代理模式的偽代碼

小白不懂題目的意思,難道是偽造CURL來源IP?
不過偽造IP倒也是必須用代理
比如: curl_setopt($curl, CURLOPT_PROXY, "http://116.236.216.116:8080/");

Ⅶ 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";

Ⅷ 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;
}

Ⅸ 如何給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

幫你編一段測試代碼,樓主試試吧!

<?PHP

if ($_SERVER['HTTP_X_FORWARDED_FOR'] == "")
{
echo '您的IP地址是:'.$_SERVER['HTTP_X_FORWARDED_FOR']."
";
echo '沒有使用代理。
'
}
else
{
echo '您的IP地址是:'.$_SERVER['HTTP_X_FORWARDED_FOR']."
";
echo '代理的IP地址:'.$_SERVER['REMOTE_ADDR'].'
';
}

?>

這代碼只能正確顯示對方使用透明代理時的結果~
希望對你有幫助!

閱讀全文

與php代理代碼相關的資料

熱點內容
自己購買雲主伺服器推薦 瀏覽:419
個人所得稅java 瀏覽:759
多餘的伺服器滑道還有什麼用 瀏覽:189
pdf劈開合並 瀏覽:26
不能修改的pdf 瀏覽:748
同城公眾源碼 瀏覽:488
一個伺服器2個埠怎麼映射 瀏覽:297
java字元串ascii碼 瀏覽:78
台灣雲伺服器怎麼租伺服器 瀏覽:475
旅遊手機網站源碼 瀏覽:332
android關聯表 瀏覽:945
安卓導航無聲音怎麼維修 瀏覽:332
app怎麼裝視頻 瀏覽:430
安卓系統下的軟體怎麼移到桌面 瀏覽:96
windows拷貝到linux 瀏覽:772
mdr軟體解壓和別人不一樣 瀏覽:904
單片機串列通信有什麼好處 瀏覽:340
游戲開發程序員書籍 瀏覽:860
pdf中圖片修改 瀏覽:288
匯編編譯後 瀏覽:491