解析php通过cookies获取远程网页的指定代码

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

function Steal($url, $post_data = ""){
//$header[] = "Accept: text/vnd.wap.wml,*.*";  
$user_agent = "Mozilla/4.0"; 
$follow_loc = 1; 
$cookie_file ="./tmp/cook.txt"; 
$ch = @curl_init(); 
@curl_setopt($ch, CURLOPT_URL, $url); 
@curl_setopt($ch, CURLOPT_USERAGENT, $user_agent); 
@curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file); 
@curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file); 
@curl_setopt($ch, CURLOPT_HEADER, $header); 
@curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
@curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $follow_loc); 
@curl_setopt($ch, CURLOPT_TIMEOUT, 1000); 
if (trim($post_data)!= "") { 
@curl_setopt($ch, CURLOPT_POST, 1); 
@curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 

$result = @curl_exec($ch); 
@curl_close($ch); 
return $result; 
}
//获取网页代码的方法
function Cut($file,$from,$end){
$message=explode($from,$file);
  $message=explode($end,$message[1]);
if ($message[0] == "")
{
$message[0] = "<font color= '#ff0000'>无法获取内容</font>";
}
  return $message[0];
}
//截取代码的方法

相关文章

PHP中防止SQL注入攻击和XSS攻击的两个简单方法

mysql_real_escape_string() 所以得SQL语句如果有类似这样的写法:"select * from cdr where src =".$userId; 都要改成 $...

PHP5中新增stdClass 内部保留类

stdClass类是PHP的一个内部保留类,初始时没有成员变量也没成员方法,所有的魔术方法都被设置为NULL,可以使用其传递变量参数,但是没有可以调用的方法。stdClass类可以被继承...

10个简化PHP开发的工具

10个简化PHP开发的工具

本文介绍了可以帮助简化 PHP 开发的10个项目,包括框架,类库,工具,代码。 1.CakePHP Development Framework CakePHP 是一个 PHP 的快速开...

一个PHP模板,主要想体现一下思路

思路: 欲在速度和易用(主要指的是美工设计的方便性)之间取得一个平衡点.于是采用了由html文件生成php文件的办法(编译?) 也想在分离显示逻辑和分离html代码之间平衡一下 例如一个...

php DES加密算法实例分析

本文实例讲述了php DES加密算法。分享给大家供大家参考,具体如下: yii框架的DES代码 <?php /** *@see Yii CSecurityManage...