导航:首页 > 编程语言 > 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代理代码相关的资料

热点内容
自己购买云主服务器推荐 浏览:422
个人所得税java 浏览:761
多余的服务器滑道还有什么用 浏览:192
pdf劈开合并 浏览:28
不能修改的pdf 浏览:752
同城公众源码 浏览:489
一个服务器2个端口怎么映射 浏览:298
java字符串ascii码 浏览:79
台湾云服务器怎么租服务器 浏览:475
旅游手机网站源码 浏览:332
android关联表 浏览:946
安卓导航无声音怎么维修 浏览:333
app怎么装视频 浏览:431
安卓系统下的软件怎么移到桌面 浏览:96
windows拷贝到linux 浏览:772
mdr软件解压和别人不一样 浏览:904
单片机串行通信有什么好处 浏览:340
游戏开发程序员书籍 浏览:860
pdf中图片修改 浏览:288
汇编编译后 浏览:491