Request page via curl with current session cookie


/ Published in: PHP
Save to your folder(s)

Request page via curl with current session cookie


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.