Description
Function to use curl() to log into a site with password and login and return the resulting page, or if specified, return another page requiring a logged-in session.
use with &login=foo&password=bar
Run
| View code [+] |
Create a snippet based on this »
View in new window »
<?php
function curl_login($login_url,$login_params,$fetch_url=false) {
$ch = curl_init($login_url);
curl_setopt ($ch, CURLOPT_POST, 1); // ENABLE HTTP POST
curl_setopt ($ch, CURLOPT_POSTFIELDS, $login_params);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); // IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // allow redirects
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HEADER , 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
if ($fetch_url) {
curl_setopt($ch, CURLOPT_URL, $fetch_url);
return curl_exec ($ch);
} else {
return curl_exec ($ch);
}
curl_close ($ch);
}
?>
Comments (1) | View comments for all versions (1)
jeff (author) said: 16 May
For a simple curl() function see curl_function
Log in if you have a Kogbox account.