Posted By

dmkim on 08/06/14


Tagged


Versions (?)

Request page via curl with current session cookie


 / Published in: PHP
 

Request page via curl with current session cookie

  1. $ch = curl_init();
  2. curl_setopt($ch, CURLOPT_HEADER,0);
  3. curl_setopt($ch, CURLOPT_URL, $url);
  4. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
  5. curl_setopt($ch, CURLOPT_TIMEOUT,10);
  6. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  7. curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0");
  8. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  9.  
  10. if (isset($_COOKIE[session_name()]))
  11. curl_setopt($ch, CURLOPT_COOKIE, session_name().'='.$_COOKIE[session_name()].'; path=/');
  12.  
  13. $result = curl_exec($ch);
  14.  
  15. if (curl_errno($ch)) {
  16.  
  17. echo 'curl error: '.curl_error($ch);
  18. }
  19.  
  20. curl_close($ch);

Report this snippet  

You need to login to post a comment.