Skip to content

Instantly share code, notes, and snippets.

@rcrowley
Created July 30, 2009 18:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcrowley/158815 to your computer and use it in GitHub Desktop.
Save rcrowley/158815 to your computer and use it in GitHub Desktop.
curl_quickie
<?php
function curl_quickie($url, $post = false, $cookie = false,
$return_headers = false, $print = false) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if (false !== $post) {
curl_setopt($ch, CURLOPT_POST, true);
if (is_array($post)) { $post = http_build_query($post); }
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
}
if ($cookie) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Cookie' => $cookie));
}
if ($return_headers) { curl_setopt($ch, CURLOPT_HEADER, true); }
if ($print) {
curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $status;
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$raw = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return array($status, $raw);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment