<?php!extension_loaded (' curl ') && die (' The curl extension are not loaded. '); $BASEURL = ' http://127.0.0.1 ';//root address $login _url = $baseUrl. ' /login.php?act=login ';//login page address $get _url = $baseUrl. ' /index.php '; The page to be collected $post _fields = Array (); The following two items need to be modified $post _fields[' name '] = ' admin '; $post _fields[' pass ' = ' 123456 '; Get form Formhash $ch = Curl_init ($login _url); curl_setopt ($ch, Curlopt_header, 0); curl_setopt ($ch, Curlopt_returntransfer, 1); $contents = curl_exec ($ch); Curl_close ($ch); Post data, get cookie $cookie _file = dirname (__file__). '/cookie.txt '; $ch = Curl_init ($login _url); curl_setopt ($ch, Curlopt_header, 0); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_post, 1); curl_setopt ($ch, Curlopt_postfields, $post _fields); curl_setopt ($ch, Curlopt_cookiejar, $cookie _file); Curl_exec ($ch); Curl_close ($ch); Take the cookie above to get the page content you need to log in to see $ch = Curl_init ($get _url); curl_setopt ($ch, Curlopt_headeR, 0); curl_setopt ($ch, Curlopt_returntransfer, 0); curl_setopt ($ch, Curlopt_cookiefile, $cookie _file); $mycontents = curl_exec ($ch); Curl_close ($ch); Var_dump ($mycontents);
PHP Analog Remote Login