as the title
the cookie information saved locally is as follows
-sharp Netscape HTTP Cookie File
-sharp https://curl.haxx.se/docs/http-cookies.html
-sharp This file was generated by libcurl! Edit at your own risk.
-sharpHttpOnly_jiaowu.jvtc.jx.cn FALSE / FALSE 0 JSESSIONID 4617AD6BC807F226E447CB9580274A23
< H2 > curl usage code is as follows < / H2 >
...
//
function login_init($url,$cookie) {
$ch = curl_init();
curl_setopt($ch , CURLOPT_URL , $url);
curl_setopt($ch , CURLOPT_RETURNTRANSFER , 1); //
curl_setopt($ch , CURLOPT_COOKIEJAR , $cookie); // cookie
curl_exec($ch);
curl_close($ch);
}
....
//
function getVerfyCode($url,$cookie) {
$ch = curl_init($url);
curl_setopt($ch , CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch , CURLOPT_RETURNTRANSFER , 1); //
$img = curl_exec($ch);
curl_close($ch);
$fp = fopen("verifyCode.jpg","w");
fwrite($fp,$img);
fclose($fp); //
// code
return currentImg("verifyCode.jpg");
}
//
login_init($url,$cookie_file);
//
$code = getVerfyCode($verify_code_url,$cookie_file);
//
$p["userAccount"] = "163050581";
$p["userPassword"] = "163050581";
$p["RANDOMCODE"] = $code;
$encoded = getEncoded("http://jiaowu.jvtc.jx.cn/Logon.do?method=logon&flag=sess",$cookie_file);
$p["encoded"] = $encoded;
login($post_url , $cookie_file,$p); //
echo "";
//
getPage("http://jiaowu.jvtc.jx.cn/jsxsd/xskb/xskb_list.do",$cookie_file);
//
function getPage($url , $cookie){
$header = array(
"Referer: http://jiaowu.jvtc.jx.cn/jsxsd/framework/xsMain.jsp",
"Accept-Language: zh-CN,zh;q=0.9",
"Host: jiaowu.jvtc.jx.cn",
"Upgrade-Insecure-Requests: 1",
"User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36"
);
$ch = curl_init();
curl_setopt($ch , CURLOPT_URL , $url);
curl_setopt($ch , CURLOPT_HEADER,1); // header
curl_setopt($ch , CURLOPT_RETURNTRANSFER , 0); //
curl_setopt($ch , CURLOPT_COOKIEFILE, $cookie);// cookie
curl_setopt($ch , CURLOPT_HTTPHEADER, $header);
$page = curl_exec($ch); //curl
curl_close($ch);
}
< H2 > shouldn"t you be logged in? < / H2 >
the final information is as follows. I confirmed that the cookie remains the same before and after login, so I should be able to get information normally after login. I read a lot of sample code. It should be like this. There is no problem with the request. Solve it
Source code address: https://github.com/RA31/login.