Web Hosting Talk







View Full Version : Curl (PHP)login to https


php_techy
06-22-2009, 01:41 AM
Hi,
Please excuse if similar issue has been posted earlier.
My scenario is
Login to a https site .
Once I login,I find a link to download a file.
Now all this I want to do with the help of curl.
I want the script in PHP for
1) login to https site
2)download the file?After applying the regex,I can get the link of the file easily but problem comes for downloading the file?Do I have to use JavaScript for that or use location header to redirect to file download link?
Thanks in advance

Kohrar
06-22-2009, 01:59 AM
Well, using curl to login is pretty easy, just set your options to use SSL, set your post data (your username and login) and execute the request to get the contents.

Here's something what I would do, but don't bark at me if it doesn't work. ;)

$c = curl_init($loginurl);

// Use SSL
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($c, CURLOPT_SSL_VERIFYHOST, 2);

curl_setopt($c, CURLOPT_POSTFIELDS, $loginDetails);
curl_setopt($c, CURLOPT_RETURNTRANSFER, TRUE);

$html = curl_exec($c);
curl_close($c);


Downloading a file is also pretty easy, just set CURLOPT_FILE to the file name, and execute the request to the download the file.