Skip to content

Instantly share code, notes, and snippets.

@saurindashadia
Last active August 13, 2017 04:51
Show Gist options
  • Save saurindashadia/0607d04fa98f662fb6e595036ee5b597 to your computer and use it in GitHub Desktop.
Save saurindashadia/0607d04fa98f662fb6e595036ee5b597 to your computer and use it in GitHub Desktop.
PHP CURL GET Example with cookies
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'www.google.com');
curl_setopt($ch, CURLOPT_POST, false);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, './cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, './cookies.txt');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment