- 论坛徽章:
- 0
|
google到一个例子
- <?
- $id = "yahoo_id";
- $pw = "yahoo_pw";
- $LOGINURL = "https://edit.tpe.yahoo.com/config/login?bqsjo61g56sg4";
- $GETURL = "http://tw.user.bid.yahoo.com/tw/show/myaucs";
- $POSTFIELDS = "login=$id&passwd=$pw";
- $user_agent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
- function AUTH_SITE_COOKIE_STORE($LOGINURL, $POSTFIELDS) {
- global $id;
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_COOKIEJAR, "$id.cookie");
- curl_setopt($ch, CURLOPT_URL, "$LOGINURL");
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, "$POSTFIELDS");
- curl_exec($ch);
- curl_close ($ch);
- return "$id.cookie";
- }
- function AUTH_SITE_GET($GETURL, $cookieFile) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_COOKIEFILE, "$cookieFile");
- curl_setopt($ch, CURLOPT_URL, "$GETURL");
- curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
- $result = curl_exec($ch);
- curl_close ($ch);
- return $result;
- }
- $cookieFile = "$id.cookie";
- $result = AUTH_SITE_GET($GETURL, $cookieFile);
- if($result == 1) {
- if(file_exists($cookieFile)) unlink($cookieFile);
- $cookieFile = AUTH_SITE_COOKIE_STORE($LOGINURL, $POSTFIELDS);
- $result = AUTH_SITE_GET($GETURL, $cookieFile);
- }
- echo $result;
- ?>
复制代码 |
|