当前位置:首页 » 编程语言 » 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; } } ?>

热点内容
树莓派如何搭建mqtt服务器 发布:2024-05-17 18:27:38 浏览:436
门口机sip服务器ip是什么 发布:2024-05-17 17:38:27 浏览:553
光遇安卓区是什么服 发布:2024-05-17 17:22:25 浏览:24
linux驱动开发教程 发布:2024-05-17 17:19:52 浏览:501
抖音中秋节视频脚本 发布:2024-05-17 17:19:51 浏览:194
快递柜为什么用安卓系统 发布:2024-05-17 17:17:18 浏览:907
电脑配置光纤接口怎么标注 发布:2024-05-17 17:06:56 浏览:977
如何用方向键控制安卓机 发布:2024-05-17 16:38:11 浏览:199
雨田系统源码 发布:2024-05-17 16:28:06 浏览:587
新手直播脚本 发布:2024-05-17 16:27:25 浏览:848