curl的一些玩意

飘逸的风14年前 (2012-11-15)程序7526
最近在想是否可以打通各家微博,显然,新浪的没有什么难度,三下五除二就能够用curl撂倒。而腾讯就不太好做,各个登录入口都有图片验证,图片识别可就难度大了,可看某篇文章,看似也就是md5的问题,不需要图片识别。

登录网站的核心是cookie的问题,另外就是对代码的分析。

做个cookie的小实验:

need-cookie.php
<?
if($_GET['login']){
  $value = 'https://www.aslibra.com';
  setcookie("url", $value);
  exit;
}

if($_COOKIE['url']){
  echo "thanks! your value is ".$_COOKIE['url'];
}else{
  echo "Not permit";
}
?>


index.php
<pre>
<?
$url = "https://www.aslibra.com/teach/curl/need-cookie.php";
$ckfile = "cookie.txt";

echo "== step 1 / no cookie ==\n";
$content = file_get_contents($url);
echo $content."\n\n";

echo "== step 2 / login ==\n";
$ch = curl_init( $url."?login=1");
curl_setopt($ch, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($ch, CURLOPT_HEADER, 1);
$r = curl_exec($ch);
echo $r."\n\n";

echo "== step 3 / get it with cookie ==\n";
$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);
$r = curl_exec($ch);
echo $r."\n\n";

?>


执行结果:

== step 1 / no cookie ==
Not permit

== step 2 / login ==
HTTP/1.1 200 OK
Date: Sat, 04 Sep 2010 08:37:06 GMT
Server: Apache/2.2.12 (Ubuntu)
X-Powered-By: PHP/5.2.10-2ubuntu6.4
Set-Cookie: url=http%3A%2F%2Fwww.aslibra.com
Vary: Accept-Encoding
Content-Length: 0
Content-Type: text/html

1

== step 3 / get it with cookie ==
thanks! your value is https://www.aslibra.com1


注意:第二步是有set-cookie的返回

 

原创内容来自 阿权的书房 

相关文章

用php解析html

注:分析html的好东西 最近想用php写一个爬虫,就需要解析html,在sourceforge上找到一个项目叫做PHP Simple HTML DOM Parser,它可以以类似jQuery的...

用PHP判断一个gif图片是不是动画

01 <?php 02 function IsAnimatedGif($filename) 03 { 04  &...

MemCache安装使用

Windows下的Memcache安装: 1. 下载memcache的windows稳定版,解压放某个盘下面,比如在c:\memcached 2. 在终端(也即cmd命令界面)下输入 ‘c:\me...

php日历的高效写法

标题写的吸引人了些,不过我就觉得是挺高效的,我相信 之前看到过 irlvirus 写的 《php练习代码-日历》,我觉得效率都不是很好。 date()函数结合mktime() 可以得到一切东西...

PHP购物车类,简单易用,移植CodeIgniter,并进行一些优化[附带实例]

个人感觉CodeIgniter用起来方便,但有时候做电子商城网站的时候,没有使用CodeIgniter框架,但想用CodeIgniter里的购物车程序,那么就需要对其购物车类进行修改。但CodeIgn...

PHP攻击网站防御代码-以及攻击代码反译

这是我无意中攻击一个网站发现的一个代码PHP有效的拦截住我的DDOS  <?php   //查询禁止IP   $ip =$_SERVER['R...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。