Login via PHP Request

Source: Internet
Author: User

<?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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.