Last active
August 29, 2015 14:02
-
-
Save dduleone/b6db407fb55a1ec7eb55 to your computer and use it in GitHub Desktop.
cURL Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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