Master please, curl simulated login problem I want to do a simulated login, but the general website has a form submitted can simulate login successful is another site, such as AliExpress (https://login.aliexpress.com /) my code is written here & lt ;? Phpfunction & nbsp; vlogin ($ url, $ expert please come in, curl simulated login problem
I want to perform a simulated login. However, if a website has submitted a form, the simulated login is successful.
Is another site, such as AliExpress (https://login.aliexpress.com /)
My code is written here.
Function vlogin ($ url, $ request ){
$ Cookie_jar = tempnam ('./tmp', 'cooker'); // generate a temporary file with a random file name in the current directory
$ Ch = curl_init (); // initialize the curl module
Curl_setopt ($ ch, CURLOPT_URL, $ url); // logon page address
Curl_setopt ($ ch, CURLOPT_POST, 1); // post method submission
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ request); // content to be submitted
// Save the cookie information returned from $ cookie_jar in the $ cookie_jar file.
Curl_setopt ($ ch, CURLOPT_COOKIEJAR, $ cookie_jar );
// Set whether the returned data is automatically displayed
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
// Set whether to display the header information
Curl_setopt ($ ch, CURLOPT_HEADER, false );
// Set whether to output the page content
Curl_setopt ($ ch, CURLOPT_NOBODY, false );
Curl_exec ($ ch );
Curl_close ($ ch); // get data after login
Return $ cookie_jar;
}
// Obtain the page content through cookies after successful logon
Function get_content_by_cookie ($ url, $ cookie_jar ){
$ Ch2 = curl_init ();
Curl_setopt ($ ch2, CURLOPT_URL, $ url );
Curl_setopt ($ ch2, CURLOPT_HEADER, false );
Curl_setopt ($ ch2, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch2, CURLOPT_COOKIEFILE, $ cookie_jar );
$ Orders = curl_exec ($ ch2 );
Curl_close ($ ch2 );
Return $ orders;
}
Function clear_cookie ($ cookie_tmp_name ){
@ Unlink ($ cookie_tmp_name );
}
$ List_url = 'http: // cn. AE .alibaba.com/index.htm ';
$ Login_url = 'https: // login.aliexpress.com /';
$ Post_data = 'PD = aliexpress & xloginPassport = ****** & xloginPassword = ******';
$ Cookie_file = vlogin ($ login_url, $ post_data );
$ Tmp_curl = get_content_by_cookie ($ list_url, $ cookie_file );
Echo $ cookie_file;
Echo $ tmp_curl;
// Clear_cookie ($ cookie_file );
?>
However, the login failed. it seems that $ login_url is incorrect. Since AliExpress does not submit the log through form, my JS base is not very good and I cannot understand his code. please click here!
Thank you!
------ Solution --------------------
You can modify the vlogin function to check the response header and body.
Function vlogin ($ url, $ request ){
$ Cookie_jar = tempnam ('./tmp', 'cooker'); // generate a temporary file with a random file name in the current directory
$ Ch = curl_init (); // initialize the curl module