PHP本地执行放在远程服务器上的脚本
<?php

//file文件中存放的是要执行的php脚本
$file="http://www.abc.com/abc.php";

if (!
remote_file_exists($file))
{
     
error_info();
} else {
     
$string=http_get($file);
     eval(
$string);

}

function 
error_info()
{
     
$str$_SERVER['REQUEST_URI'];
     if (
strstr($str,"?"))
     {
             
$serexplode("/",$_SERVER['REQUEST_URI']);
             
$errfile=explode("?"$ser[2]);
             
$errorfile=$errfile[0];
     }
     else
     {
             
$errfileexplode("/",$_SERVER['REQUEST_URI']);
             
$errorfile=$errfile[2];
     }
     
$errorinfo="
             <!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">
             <html><head>
             <title>404 Not Found</title>
             </head><body>
             <h1>Not Found</h1>
             <p>The requested URL /$errorfile
             was not found on this server.</p>
             </body></html>"
;
     echo 
$errorinfo;
     exit;
}

function 
http_get($url)
{

     
$url_stuff parse_url($url);
     
$port = isset($url_stuff['port']) ? $url_stuff['port'] : 80;

     
$fp fsockopen($url_stuff['host'], $port);

     
$query     'GET ' $url_stuff['path'] . " HTTP/1.0\n";
     
$query .= 'Host: ' $url_stuff['host'];
     
$query .= "\n\n";

     
fwrite($fp$query);

     while (
$tmp fread($fp1024))
     {
             
$buffer .= $tmp;
     }

     
preg_match('/Content-Length: ([0-9]+)/'$buffer$parts);
     return 
substr($buffer, - $parts[1]); 
}

function 
remote_file_exists($url_file){
     
//检测输入
     
$url_file trim($url_file);
     if (empty(
$url_file)) { return false; }
     
$url_arr parse_url($url_file);
     if (!
is_array($url_arr) || empty($url_arr)){ return false; }

     
//获取请求数据
     
$host $url_arr['host'];
     
$path $url_arr['path'] ."?"$url_arr['query'];
     
$port = isset($url_arr['port']) ? $url_arr['port'] : "80";

     
//连接服务器
     
$fp fsockopen($host$port$err_no$err_str30);
     if (!
$fp){ return false; }

     
//构造请求协议
     
$request_str "GET ".$path." HTTP/1.1\r\n";
     
$request_str .= "Host: ".$host."\r\n";
     
$request_str .= "Connection: Close\r\n\r\n";

     
//发送请求
     
fwrite($fp$request_str);
     
$first_header fgets($fp1024);
     
fclose($fp);

     
//判断文件是否存在
     
if (trim($first_header) == ""){ return false; }
     if (!
preg_match("/200/"$first_header)){
             return 
false;
     }
     return 
true;
}

?>
« 上一篇 | 下一篇 »
只显示10条记录相关文章
php header 跳转 (浏览: 451, 评论: 0)
定时清理旧的log文件 (浏览: 1806, 评论: 1)
FIREFOX取动态input值 (浏览: 1158, 评论: 0)
用css方式巧妙保护邮箱地址 (浏览: 1183, 评论: 0)
PHP5_OOP面向对象---教程下载 (浏览: 2299, 评论: 0)
vc++中用ado连接oracle数据库 (浏览: 4173, 评论: 0)
在DISDUZ!5.5中添加代码高亮插件成功 (浏览: 3123, 评论: 1)
xajax+php的一个DEMO--Blackjack(21点) (浏览: 3503, 评论: 3)
关于使用PHP6的感受 (浏览: 2736, 评论: 0)
[PHP AJAX] 简单比较 xajax、AJASON、flxAJAX、Aja... (浏览: 2711, 评论: 0)
Trackbacks
点击获得Trackback地址,Encode: UTF-8 点击获得Trackback地址,Encode: GB2312 or GBK 点击获得Trackback地址,Encode: BIG5
发表评论

评论内容(*):