Skip to content

Instantly share code, notes, and snippets.

@dduleone
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save dduleone/b6db407fb55a1ec7eb55 to your computer and use it in GitHub Desktop.

Select an option

Save dduleone/b6db407fb55a1ec7eb55 to your computer and use it in GitHub Desktop.
cURL Example
<?php
// To write/create session cookie
function initSession ($url, $cookie) {
$curlConfig = array(
CURLOPT_URL => $url, // URL you're accessing
CURLOPT_RETURNTRANSFER => true,
CURLOPT_COOKIEJAR => $cookie, // Path to cookie file
CURLINFO_HEADER_OUT => true,
);
$ch = curl_init();
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
// To use established session cookie
function callUrl ($url, $cookie) {
$curlConfig = array(
CURLOPT_URL => $url,
CURLOPT_CONNECTTIMEOUT => 0,
CURLOPT_TIMEOUT => 360,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_COOKIEFILE => $cookie,
);
$ch = curl_init();
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment