Incorrect verification code is always displayed during simulated login using curl. Header ("Content-type: text/html; charset = gb2312 ");
$ CookieFile = tempnam ("./tmep", "beast ");
If (isset ($ _ GET ["img"]) {
$ Url = 'http: // export c.wyu.edu.cn/student/rndnum.asp'#//verify the code
$ Ch = curl_init ($ url );
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ CookieFile); // Save the returned cookie information to the file
Curl_exec ($ ch );
Curl_close ($ ch );
Exit ();
}
If (isset ($ _ POST ['D']) {
$ B = $ _ POST ['D']; // verification code
$ P = "UserCode = 3114002555 & UserPwd = don't tell you & Validate =". $ B. "& Submit = Submit ";
$ Ch = curl_init ();
// 2. set options, including URL
$ Reffer = 'http: // export c.wyu.edu.cn/student/body.htm ';
Curl_setopt ($ ch, CURLOPT_REFERER, $ reffer );
Curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64; rv: 39.0) Gecko/20100101 Firefox/39.0 ");
Curl_setopt ($ ch, CURLOPT_URL, "http://jwc.wyu.edu.cn/student/logon.asp ");
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ CookieFile );
Curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ CookieFile); // send Cookie at the same time
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ p); // submit the query information.
$ S = curl_exec ($ ch );
Curl_close ($ ch );
$ Ch = curl_init ();
$ Reffer = 'http: // export c.wyu.edu.cn/student/body.htm ';
Curl_setopt ($ ch, CURLOPT_REFERER, $ reffer );
Curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.3; WOW64; rv: 39.0) Gecko/20100101 Firefox/39.0 ");
Curl_setopt ($ ch, CURLOPT_URL, "http://jwc.wyu.edu.cn/student/logon.asp ");
Curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true );
Curl_setopt ($ ch, CURLOPT_COOKIEFILE, $ CookieFile); // send Cookie at the same time
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ CookieFile );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_POST, 1 );
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ p); // submit the query information.
$ Bs = curl_exec ($ ch );
Echo $ bs; // output result
Curl_close ($ ch );
} Else {
?>
}
?>
Reply to discussion (solution)
$url = 'http://jwc.wyu.edu.cn/student/';print_r(get_headers($url));
Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: private
[2] => Connection: close
[3] => Date: Mon, 24 Aug 2015 11:30:29 GMT
[4] => Content-Length: 617
[5] => Content-Type: text/html
[6] => Set-Cookie: ASPSESSIONIDCQAATSAR = HGOCKONAKIMOPBIOFJFHPGFI; path =/
[7] => Server: IIS
[8] => X-Powered-By: WAF/2.0
[9] => Set-Cookie: safedog-flow-item = 6BFDB3BC0A21C98B7224B81C2C04C934; expires = Mon, 24-Aug-2015 16:00:29 GMT; domain = wyu.edu.cn; path =/
)
When you access the home page, you already have a session. you cannot read the verification code without it.
How to bring the session and where to bring it
$url = 'http://jwc.wyu.edu.cn/student/';print_r(get_headers($url));
Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: private
[2] => Connection: close
[3] => Date: Mon, 24 Aug 2015 11:30:29 GMT
[4] => Content-Length: 617
[5] => Content-Type: text/html
[6] => Set-Cookie: ASPSESSIONIDCQAATSAR = HGOCKONAKIMOPBIOFJFHPGFI; path =/
[7] => Server: IIS
[8] => X-Powered-By: WAF/2.0
[9] => Set-Cookie: safedog-flow-item = 6BFDB3BC0A21C98B7224B81C2C04C934; expires = Mon, 24-Aug-2015 16:00:29 GMT; domain = wyu.edu.cn; path =/
)
When you access the home page, you already have a session. you cannot read the verification code without it.
Why didn't I learn it for a long time? curl has been around for a long time. can you tell me?
$url = 'http://jwc.wyu.edu.cn/student/';print_r(get_headers($url));
Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: private
[2] => Connection: close
[3] => Date: Mon, 24 Aug 2015 11:30:29 GMT
[4] => Content-Length: 617
[5] => Content-Type: text/html
[6] => Set-Cookie: ASPSESSIONIDCQAATSAR = HGOCKONAKIMOPBIOFJFHPGFI; path =/
[7] => Server: IIS
[8] => X-Powered-By: WAF/2.0
[9] => Set-Cookie: safedog-flow-item = 6BFDB3BC0A21C98B7224B81C2C04C934; expires = Mon, 24-Aug-2015 16:00:29 GMT; domain = wyu.edu.cn; path =/
)
When you access the home page, you already have a session. you cannot read the verification code without it.
You can use curl_setopt ($ ch, CURLOPT_HTTPHEADER, "Set-Cookie: ASPSESSIONIDCQAATSAR = HGOCKONAKIMOPBIOFJFHPGFI; path = /");
$url = 'http://jwc.wyu.edu.cn/student/';print_r(get_headers($url));
Array
(
[0] => HTTP/1.1 200 OK
[1] => Cache-Control: private
[2] => Connection: close
[3] => Date: Mon, 24 Aug 2015 11:30:29 GMT
[4] => Content-Length: 617
[5] => Content-Type: text/html
[6] => Set-Cookie: ASPSESSIONIDCQAATSAR = HGOCKONAKIMOPBIOFJFHPGFI; path =/
[7] => Server: IIS
[8] => X-Powered-By: WAF/2.0
[9] => Set-Cookie: safedog-flow-item = 6BFDB3BC0A21C98B7224B81C2C04C934; expires = Mon, 24-Aug-2015 16:00:29 GMT; domain = wyu.edu.cn; path =/
)
When you access the home page, you already have a session. you cannot read the verification code without it.
Thank you very much for the successful simulated login.