Jump to content

cURL / Copy() with HTTPS not working


tommyboy123x

Recommended Posts

For some reason when I attempt to connect to the server to download the log file (it has get variables to specify the date range), it won't work

 

Also, this code is extremely... "simplified" and yet so ugly  :D

 

$url = 'http://..../'; #an example URL
$password = 'password';
$username = 'username';
filename = 'filename';

$file = 'csvuploads/'.$filename;
$timestamp = time();
$em = date('n', $timestamp); #end month
$ed = date('j', $timestamp); #end day
$ey = date('Y', $timestamp); #end year
$timestamp2 = $timestamp - 150000;
$sm = date('n', $timestamp2); #etc...
$sd = date('j', $timestamp2);
$sy = date('Y', $timestamp2);
$url0 = str_replace('{ey}',$ey,$url);
$url1 = str_replace('{sm}',$sm,$url0);
$url2 = str_replace('{sd}',$sd,$url1);
$url3 = str_replace('{sy}',$sy,$url2);
$url4 = str_replace('{em}',$em,$url3);
$url = str_replace('{ed}',$ed,$url4);
$ch = curl_init();
$handle = fopen($file, 'w+');
echo 'em: '.$em.'<br />ed: '.$ed.'<br />ey: '.$ey.'<br />sm: '.$sm.'<br />sd: '.$sd.'<br />sy: '.$sy.'<br />url: '.$url.'<br />username: '.$row['username'].'<br />password: '.$row['password'].'<br />';
curl_setopt($ch, CURLOPT_COOKIEJAR, "inc/cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "inc/cookies.txt");
//curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERPWD, $username.':'.$password);
curl_setopt($ch, CURLOPT_FILE, $handle);
if (!curl_exec($ch)){
echo 'An error has occured!<br />Code: 8523x8';
exit();
}
curl_close($ch);

 

It creates the file and can output the data, however it gets hung up on the curl_exec(), where it doesn't connect properly.  It loads for about 30 seconds and then gives up.  Any advice?

 

Also, I've tried copy() with even less luck using https://username:[email protected]/....etc.../.

 

Help appreciated!

Link to comment
https://forums.phpfreaks.com/topic/114808-curl-copy-with-https-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.