PHP代码
- <?php
- /*
- 用PHP程序如何模拟用户登录yahoo空间(http://i.cn.yahoo.com/)。所谓的“模拟用户登录”是指用写支PHP程序模拟用户登录
- 的过程。
- */
- //登陆成功则会提示succeed 失败则自动转向yahoo出错页
- loginYahoo(‘cnphpd@yahoo.com’,‘******’);
- function loginYahoo($user,$pass){
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, "https://edit.bjs.yahoo.com/config/login");
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
- curl_setopt($ch, CURLOPT_POSTFIELDS,‘login=’.$user.‘&passwd=’.$pass.‘&.persistent=y’);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- $result = curl_exec($ch) or die (curl_error($ch));
- echo $result;
- echo curl_error($ch);
- curl_close($ch);
- //判断是否登陆成功!
- $ch2 = curl_init();
- curl_setopt($ch2, CURLOPT_URL, "http://i.cn.yahoo.com/my.html?.login=1");
- curl_setopt($ch2, CURLOPT_SSL_VERIFYPEER, FALSE);
- curl_setopt($ch2, CURLOPT_SSL_VERIFYHOST, 2);
- $result2 =curl_exec($ch2);
- curl_close($ch2);
- if($result2==1){
- echo ‘succeed’;
- }else{
- echo ‘error’;
- }
- }
- ?>
good