I. Defining a cookie Storage path
Absolute path must be used
$cookie _jar = dirname (__file__). " /pic.cookie ";
$cookie _file = dirname (__file__). ' /cookie.txt ';
$cookie _file = Tempnam ("tmp", "Cookie");
Second, access to cookies
$url = "http://1.2.3.4/";
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, $url);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, Curlopt_returntransfer, true);
curl_setopt ($ch, Curlopt_cookiejar, $cookie _jar);
$content = curl_exec ($ch);
Curl_close ($ch);
Third, the simulation browser to obtain the verification code
The server verification code is a vulnerability, you can specify
Take out the cookie and submit it to the server to let the server think it is the browser to open the landing page
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, ' http://1.2.3.4/getCheckpic.action?rand=6836.185874812305 ');
curl_setopt ($ch, Curlopt_cookiefile, $cookie _jar);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, Curlopt_returntransfer, 1);
$ret = curl_exec ($ch);
Curl_close ($ch);
Iv. Post Submission
$post = "name=2&usertype=1&passwd=asdf&logintype=1&rand=6836&imagefield.x=25& Imagefield.y=7 ";
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, "http://1.2.3.4/loginstudent.action");
curl_setopt ($ch, Curlopt_header, false);
curl_setopt ($ch, curlopt_returntransfer,1);
curl_setopt ($ch, Curlopt_postfields, $post);
curl_setopt ($ch, Curlopt_cookiefile, $cookie _jar);
$result =curl_exec ($ch);
Curl_close ($ch);
Five, to the specified page to obtain data
$ch = Curl_init ();
curl_setopt ($ch, Curlopt_url, "http://1.2.3.4/accountcardUser.action");
curl_setopt ($ch, Curlopt_header, false);
curl_setopt ($ch, Curlopt_header, 0);
curl_setopt ($ch, curlopt_returntransfer,0);
curl_setopt ($ch, Curlopt_cookiefile, $cookie _jar);
$html =curl_exec ($ch);
Var_dump ($html);
Curl_close ($ch);
PHP Get cookie Emulation Login