note 57005 added to ref.curl

From: Date: Wed, 21 Sep 2005 14:09:05 +0000
Subject: note 57005 added to ref.curl
Groups: php.notes 
Request: Send a blank email to php-notes+get-95533@lists.php.net to get a copy of this message
/* Here is a script that is usefull to : - login to a POST form, - store a session cookie, - download a file once logged in. */ // INIT CURL $ch = curl_init(); // SET URL FOR THE POST FORM LOGIN curl_setopt($ch, CURLOPT_URL, 'http://www.external-site.com/Members/Login.php'); // ENABLE HTTP POST curl_setopt ($ch, CURLOPT_POST, 1); // SET POST PARAMETERS : FORM VALUES FOR EACH FIELD curl_setopt ($ch, CURLOPT_POSTFIELDS, 'fieldname1=fieldvalue1&fieldname2=fieldvalue2'); // IMITATE CLASSIC BROWSER'S BEHAVIOUR : HANDLE COOKIES curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); # Setting CURLOPT_RETURNTRANSFER variable to 1 will force cURL # not to print out the results of its query. # Instead, it will return the results as a string return value # from curl_exec() instead of the usual true/false. curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); // EXECUTE 1st REQUEST (FORM LOGIN) $store = curl_exec ($ch); // SET FILE TO DOWNLOAD curl_setopt($ch, CURLOPT_URL, 'http://www.external-site.com/Members/Downloads/AnnualReport.pdf'); // EXECUTE 2nd REQUEST (FILE DOWNLOAD) $content = curl_exec ($ch); // CLOSE CURL curl_close ($ch); /* At this point you can do do whatever you want with the downloaded file stored in $content : display it, save it as file, and so on. */ ---- Manual Page -- http://www.php.net/manual/en/ref.curl.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+57005 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+57005&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+57005&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+57005&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+57005&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+57005&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+57005&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+57005&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+57005&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#95533) next »