Home > Backend Development > PHP Tutorial > Curl does not use file access cookies. PHP uses curl to obtain cookies. Example_PHP tutorial

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:39:47
Original
1095 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:
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
Latest Issues
curl simulated login
From 1970-01-01 08:00:00
0
0
0
Convert cURL command line to PHP cURL code
From 1970-01-01 08:00:00
0
0
0
Convert command line cURL to PHP cURL
From 1970-01-01 08:00:00
0
0
0
How to set boolean value true in php curl
From 1970-01-01 08:00:00
0
0
0
Please tell me, php curl request page shows blank
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template