curl的一些玩意
最近在想是否可以打通各家微博,显然,新浪的没有什么难度,三下五除二就能够用curl撂倒。而腾讯就不太好做,各个登录入口都有图片验证,图片识别可就难度大了,可看某篇文章,看似也就是md5的问题,不需要图片识别。
登录网站的核心是cookie的问题,另外就是对代码的分析。
做个cookie的小实验:
need-cookie.php
index.php
执行结果:
登录网站的核心是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";
}
?>
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";
?>
<?
$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
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的返回
原创内容来自 阿权的书房