Home >Backend Development >PHP Tutorial >php curl storage cookie instance

php curl storage cookie instance

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:12:541095browse

例子,php使用curl存储cookie。

  1. $curl = curl_init();
  2. $url = 'http://bbs.it-home.org/login';
  3. $data = array(
  4. 'username'=>'admin',
  5. 'password'=>'123'
  6. );
  7. $cookie = tempnam('./temp','cookie');
  8. curl_setopt($curl,CURLOPT_URL,$url);
  9. curl_setopt($curl,CURLOPT_POST,count($data));
  10. curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
  11. curl_setopt($curl,CURLOPT_COOKIEJAR,$cookie);
  12. ob_start();
  13. curl_exec($curl);
  14. $result = ob_get_contents();
  15. ob_end_clean();
  16. curl_close($curl);
复制代码


Statement:
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