PHP Get cookie Emulation Login

Source: Internet
Author: User

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

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.