Get Cookies from Php Curl

By Thanh Tùng   Posted at  tháng 2 14, 2019   PHP No comments
Kết quả hình ảnh cho PHP
  1. <?php
  2. $ch = curl_init(http://www.google.com/’);
  3. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  4. curl_setopt($ch, CURLOPT_HEADER, 1);
  5. $result = curl_exec($ch);
  6. preg_match_all(‘/^Set-Cookie:\s*([^;]*)/mi’, $result, $matches); // get cookie
  7. $cookies = array();
  8. foreach($matches[1] as $item) {
  9. parse_str($item, $cookie);
  10. $cookies = array_merge($cookies, $cookie);
  11. }
  12. var_dump($cookies);
  13. ?>

About Thanh Tùng

Nulla sagittis convallis arcu. Sed sed nunc. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.
View all posts by: Thanh Tùng

0 nhận xét:

Connect with Us

Powered by Blogger.
back to top