Home > Backend Development > PHP Tutorial > PHP curl simulated login_PHP tutorial

PHP curl simulated login_PHP tutorial

WBOY
Release: 2016-07-13 10:36:40
Original
1057 people have browsed it

//Submit data, generate cookies, and save cookies in the temporary directory
//Create a file with a unique file name in the specified directory. If the directory does not exist, tempnam() will generate a file in the system temporary directory and return its file name 

$cookie_file=tempnam('./temp','cookie');
$ch=curl_init();
$login_url="http://www.xxx.com/login/";
 $curlPost="username=username&password=password";
 curl_setopt($ch,CURLOPT_URL,$login_url);
 //When enabled, the information of the header file will be output as a data stream
 curl_setopt( $ch,CURLOPT_HEADER,0);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//Display http information output
curl_setopt($ch,CURLOPT_POST,1);//POST request
curl_setopt($ ch,CURLOPT_POSTFIELDS,$curlPost);//Request body
//Set the file to save cookie information after the connection is completed
curl_setopt($ch,CURLOPT_COOKIEJAR,$cookie_file);
curl_exec($ch);
curl_close($ch);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/738508.htmlTechArticle//Submit data, generate cookies, and save cookies in a temporary directory//Create a file with Unique file name for the file. If the directory does not exist, tempnam() will temporarily...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template