<?PHP/** * Created by Phpstorm. * User: Spirit Magic Museum * date:2016/5/24 0024 * Time: PM 17:07*///before you start to do a few notes, first you have to know the user name and password because it is simulated browser behavior to achieve login, the browser needs user data in order to jump to other pages//initial Curl Resources$curl=curl_init ();//Configurationcurl_setopt ($curl, Curlopt_url, ' Www.tang.com/blog/admin/user.php?a=check '); curl_setopt ($curl, Curlopt_useragent, ' TANG '); curl_setopt ($curl, Curlopt_referer, ' blog/admin/user.php ');$data=Array( ' Username ' = ' tangshuai ', ' password ' = ' Tangshuai ', ' captcha ' and ');$data _str=Http_build_query($data);$header[] = ' accept:text/html ';$header[] = ' ACCEPT-LANGUAGE:ZH-CN ';$header[] = ' connection:close ';//set the address of the cookie store$cookie _address= ' E:/tangdengshuai/apache24/htdocs/myweb3/cookie '; curl_setopt ($curl, Curlopt_cookiejar,$cookie _address); curl_setopt ($curl, Curlopt_post,true); curl_setopt ($curl, Curlopt_postfields,$data _str); curl_setopt ($curl, Curlopt_header,$header); curl_setopt ($curl, Curlopt_header,false); curl_setopt ($curl, Curlopt_returntransfer,true);//make a request$response= Curl_exec ($curl);Echo Iconv(' Utf-8 ', ' GBK ',$response);//Close ResourceCurl_close ($curl);//initializing a Curl resource$curl=curl_init ();////Carry cookies upon request$cookie _address= ' E:/tangdengshuai/apache24/htdocs/myweb3/cookie '; curl_setopt ($curl, Curlopt_cookiefile,$cookie _address);//Configure the data required for a GET requestcurl_setopt ($curl, Curlopt_url, ' www.tang.com/blog/admin/index.php ');//Configure data on the request agent sidecurl_setopt ($curl, Curlopt_useragent, ' TANG ');//Configure the request sourcecurl_setopt ($curl, Curlopt_referer, ' Www.tang.com/blog ');//Additional request header information$header[]= ' accept:text/html ';$header[]= ' ACCEPT-LANGUAGE:ZH-CN ';$header[]= ' Connection:close '; curl_setopt ($curl, Curlopt_header,$header);//the head when the output contentcurl_setopt ($curl, Curlopt_header,true);//do not output content directlycurl_setopt ($curl, Curlopt_returntransfer,true);//Send Request$response=curl_exec ($curl);Echo Iconv(' Utf-8 ', ' GBK ',$response);//Turn off Curl ResourcesCurl_close ($curl);
Login via PHP Request