curl類比登陸不成功

來源:互聯網
上載者:User
curl真蛋疼老是遇到問題- -

$cookie_file=dirname(__FILE__).'/cookie.txt';
$data='username=賬戶&password=密碼';
$curlobj=curl_init('http://passport.sundns.com/index.php?client_id=sundns');
curl_setopt($curlobj, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curlobj, CURLOPT_POST,1);
curl_setopt($curlobj, CURLOPT_POSTFIELDS,$data);
curl_setopt($curlobj, CURLOPT_COOKIEJAR,$cookie_file);
$first=curl_exec($curlobj);
curl_close($curlobj);


$curlobj=curl_init('http://www.sundns.com/member.php');
curl_setopt($curlobj, CURLOPT_RETURNTRANSFER,1);
curl_setopt($curlobj, CURLOPT_COOKIEFILE,$cookie_file);
$output=curl_exec($curlobj);
curl_close($curlobj);
echo $output;

目錄下的cookie.txt:
# Netscape HTTP Cookie File
# http://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_passport.sundns.com FALSE / FALSE 0 PHPSESSID odjcjs622gmhg5k9b2hu92m047


mysql報錯:
Not Found
The requested URL /test/login.php was not found on this server.

是想跳到個人頁面的卻報了錯,為什麼啊


回複討論(解決方案)

換了種寫法,還是不成功
$curl = curl_init();
$cookie_jar = tempnam('D:/wamp/www/test','cookie');
curl_setopt($curl, CURLOPT_URL,'http://www.nidebook.com/do/login.php');//登陸介面
curl_setopt($curl, CURLOPT_POST, 1);
$request = 'username=使用者名稱&password=密碼';
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie_jar);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_exec($curl);
curl_close($curl);

$curl2 = curl_init();
curl_setopt($curl2, CURLOPT_URL, 'http://www.nidebook.com/member/homepage.php');//個人中心
curl_setopt($curl2, CURLOPT_HEADER, false);
curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl2, CURLOPT_COOKIEFILE, $cookie_jar);
$content = curl_exec($curl2);
echo $content;

執行後還是使用者登陸介面,顯示使用者不存在,懷疑是cookie有問題

cookie裡的資料:
# Netscape HTTP Cookie File
# http://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
www.nidebook.com FALSE / FALSE 1461245580 USR eauxwntm%090%091461159180%09http%3A%2F%2Fwww.nidebook.com%2Fdo%2Flogin.php


將form 的一些hidden值也帶過去

將form 的一些hidden值也帶過去



原來是這樣,謝謝了,沒人教碰到問題真是兩眼一抹黑
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.