Curl does not use file access cookies. PHP uses curl to obtain cookies. Example_PHP tutorial

WBOY
Release: 2016-07-13 10:39:47
Original
1030 people have browsed it

Copy code The code is as follows:

/*-----Save COOKIE-----*/
$url = 'www.xxx.com'; //url address
$post = "id=user&pwd=123456"; //POST data
$ch = curl_init($url); //Initialization
curl_setopt($ch,CURLOPT_HEADER,1); //Output the header file information as a data stream
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); //Return the obtained output text stream
curl_setopt($ ch,CURLOPT_POSTFIELDS,$post); //Send POST data
$content = curl_exec($ch); //Execute curl and assign value to $content
preg_match('/Set-Cookie:(.*); /iU',$content,$str); //Regular matching
$cookie = $str[1]; //Get COOKIE (SESSIONID)
curl_close($ch); //Close curl

/*-----Use COOKIE-----*/
curl_setopt($ch,CURLOPT_COOKIE,$cookie);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/728116.htmlTechArticleCopy the code as follows: /*-----Save COOKIE-----*/ $url = 'www.xxx.com'; //url address $post = "id=user //POST data $ch = curl_init($url); //Initialize curl_setopt($ch,CURLOPT_HEA...
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