解析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操作mongoDB实例分析

本文实例讲述了php操作mongoDB的方法。分享给大家供大家参考。具体分析如下: mongoDB数据库是一种以json格式存储的数据库,非常适用于各种应用开发,这里就来给各位朋友介绍一...

微信access_token的获取开发示例

概述 access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token。开发者需要进行妥善保存。access_token的存储至少要保留512个字符空间...

浅谈PHP中JSON数据操作

JSON,全称是JavaScript Object Notation。它是基于JavaScript编程语言ECMA-262 3rd Edition-December 1999标准的一种轻...

php多个字符串替换成同一个的解决方法

复制代码 代码如下:<?php$name = 'Today 3? , very/ cold';$name = strtolower($name);//$name = preg_re...

PHP从零开始打造自己的MVC框架之类的自动加载实现方法详解

PHP从零开始打造自己的MVC框架之类的自动加载实现方法详解

本文实例讲述了PHP从零开始打造自己的MVC框架之类的自动加载实现方法。分享给大家供大家参考,具体如下: 前面介绍了MVC框架的入口文件,接下来我们希望完成一个“自动加载类”的功能,我们...