您当前的位置: 首页 > 网站编程 > PHP教程 > 解析php通过cookies获取远程网页的指定代码

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

作者:不详 来源:网络 发布时间: 2014-08-19 09:11 点击:
代码如下: 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_

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

  代码如下:

  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通过cookies获取远程网页的指定代码"由远航站长收集整理而来,仅供大家学习与参考使用。更多网站制作教程尽在远航站长站。
顶一下
(0)
0%
踩一下
(0)
0%
[点击 次] [返回上一页] [打印]
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 密码: 验证码:
关于本站 - 联系我们 - 网站声明 - 友情连接- 网站地图 - 站点地图 - 返回顶部
Copyright © 2007-2013 www.yhzhan.com(远航站长). All Rights Reserved .
远航站长:为中小站长提供最佳的学习与交流平台,提供网页制作与网站编程等各类网站制作教程.
官方QQ:445490277 网站群:26680406 网站备案号:豫ICP备07500620号-4