Code:
login.php
<?PHP$data= ' Tbusername=huangdi0912&tbpassword=******&chkremember=1 ';$curl=curl_init (); curl_setopt ($curl, Curlopt_url, ' Http://passport.cnblogs.com/login.aspx?ReturnUrl=http%3A%2F%2Fwww.cnblogs.com%2F ');//Login Pagecurl_setopt ($curl, Curlopt_returntransfer,true);//do not print results directly//set cookies, this part of the settings need to be set before all sessions startDate_default_timezone_set (' PRC ');//when using cookies, you must first set the time zonecurl_setopt ($curl, Curlopt_cookiesession,true);//enable curl to support cookies and sessioncurl_setopt ($curl, Curlopt_cookiefile, ' cookiefile ');//path of Cookie savingcurl_setopt ($curl, Curlopt_cookiejar, ' Cookiefile '); curl_setopt ($curl, Curlopt_cookie,Session_name() . ' = '.session_id());//save SessionID in Cookiescurl_setopt ($curl, Curlopt_header, 0);//make curl do not print header informationcurl_setopt ($curl, curlopt_followlocation,1);//is Curl support page link jumpcurl_setopt ($curl, curlopt_post,1);//Post Modecurl_setopt ($curl, Curlopt_postfields,$data);//set the parameters of the postcurl_setopt ($curl, Curlopt_httpheader,Array(' Application/x-www-form-urlencoded;charset=utf-8 ', ' content-length: '.strlen($data)) ; curl_setopt ($curl, Curlopt_useragent, "user-agent:mozilla/5.0 (Windows NT 5.1; rv:24.0) gecko/20100101 firefox/24.0 ");//Fix Error: "Object reference not set to an instance of an object. "Curl_exec ($curl); curl_setopt ($curl, Curlopt_url, ' http://www.cnblogs.com/dee0912/');//Personal Center Pagecurl_setopt ($curl, curlopt_post,0);//Clear Post Statuscurl_setopt ($curl, Curlopt_httpheader,Array(' Content-type:text/xml '));$output= Curl_exec ($curl); Curl_close ($curl);Echo $output;
Visit this page:
CURL Learning Notes and summaries (3) Demo login Blog Park and download personal essays Home