最近在想是否可以打通各家微博,显然,新浪的没有什么难度,三下五除二就能够用curl撂倒。而腾讯就不太好做,各个登录入口都有图片验证,图片识别可就难度大了,可看某篇文章,看似也就是md5的问题,不需要图片识别。
登录网站的核心是cookie的问题,另外就是对代码的分析。
做个cookie的小实验:
need-cookie.php
index.php
执行结果:
注意:第二步是有set-cookie的返回
备注一下几篇文章:
1 新浪微博版twitese
2 通过PHP curl向腾讯微博发送广播全过程
3 PHP cURL Cookies Example
4 csdn模拟登陆
原创内容如转载请注明:来自 阿权的书房
登录网站的核心是cookie的问题,另外就是对代码的分析。
做个cookie的小实验:
need-cookie.php
<?
if($_GET['login']){
$value = 'http://www.aslibra.com';
setcookie("url", $value);
exit;
}
if($_COOKIE['url']){
echo "thanks! your value is ".$_COOKIE['url'];
}else{
echo "Not permit";
}
?>
if($_GET['login']){
$value = 'http://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 = "http://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";
?>
<?
$url = "http://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 http://www.aslibra.com1
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 http://www.aslibra.com1
注意:第二步是有set-cookie的返回
备注一下几篇文章:
1 新浪微博版twitese
2 通过PHP curl向腾讯微博发送广播全过程
3 PHP cURL Cookies Example
4 csdn模拟登陆
原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
zhulinzi 

2011/01/11 11:33
收藏中,以后会时常过来学习的
我头痛
2010/11/19 12:32
zxqa.17taomei.com弄不出来啊,郁闷
hqlulu 回复于 2010/11/19 13:00
不懂
skyer


2010/09/06 16:14
支持个 不错
分页: 1/1
1
1
转:中国父母是如何把女孩子们逼成剩女的
转:单反不是你想买,想买就能卖
