Skip to content

Instantly share code, notes, and snippets.

@drewlesueur
Created September 30, 2010 00:22
Show Gist options
  • Save drewlesueur/603809 to your computer and use it in GitHub Desktop.
Save drewlesueur/603809 to your computer and use it in GitHub Desktop.
PHP Automater
<?php
//Use this script to automatically log into a site and grab protected info.
//code modified from
// http://www.knowledgesutra.com/forums/topic/38162-automatic-login-using-curl/
//see also
//http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/
// INIT CURL
$ch = curl_init();
//needed for https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, "cainfo_file");
// end required for https
curl_setopt($ch, CURLOPT_URL, 'https://the.tl/login.php');
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, 'username=user&password=fakepw');
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$logged_in_html = curl_exec ($ch);
curl_setopt($ch, CURLOPT_URL, 'https://the.tl/report.pdf');
$content = curl_exec ($ch);
header('Content-type: application/pdf');
echo $content;
curl_close ($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment