Provide credentials to the link using script

Hello ,

I have a link

after clicking on this link it askes me for usename and password

when i submit those credentials gets downloaded.

I want to do all this using php script.

I wanteed to set a cron for this.
and file should be downloaded at my sever.

what should i do?
curl or socekt programming ?
any idea?

How does it ask for credentials? In a web page? Or in a popup?

If it’s in a popup, then you could use cURL to request the file, and send the authentication info in the cURL request:

curl_setopt($ch, CURLOPT_USERPWD, "username:password");

in a popup

Then you could use cURL:

$url = "";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
$zip = curl_exec($ch);

Now the variable $zip contains your zip file, and you can save it to disk or do something else with it.
If it’s a large file, it’s probably best to save it to disk while downloading:

$url = "";
$fp = fopen("", "w");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_USERPWD, "username:password");

Thank you till now for the help

when i tried the code
it gives me
but the size is 0kb
no data in it
where in url zip is 8.3KB

After the above code has finished, see what curl_error() returns - it should be able to help you figure out what’s up.

Curl error: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Add this option where you’re setting the other options:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

This options makes curl assume that the SSL connection you’re connecting to is trusted and doesn’t check it against the CA’s certificate.
This means it will still download the file if someone else manages to hijack/ spoof the connection…

It’s done dear…
Thanks for the help…
u saved my time.