tags:

views:

274

answers:

2

I'm trying to use cURL to access a secure file.. The documentation for its use is confusing so I searched and found two sites (1 & 2) and a reference here on SO but the scripts don't seem to work for me.

The site I'm am trying to access has the data I need publicly available, so I don't need to log in or provide a password.

This is the script I have and all it does is sit there waiting for something to happen (I get no errors).

$ch = curl_init('https://www.somesite.com/index.htm');

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);

// Disable PEER SSL Verification: If you are not running with SSL or if you don't have valid SSL
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

// Disable HOST (the site you are sending request to) SSL Verification,
// if Host can have certificate which is nvalid / expired / not signed by authorized CA.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

$sFile = curl_exec($ch);
curl_close($ch);

I just need to figure out what I'm doing wrong here. Thanks!

Update: The script does work locally in XAMPP, but not on the live server (am I missing a php setting? - probably something I can't touch because I'm using a free hosting service, for now). I also found this article about grabbing a certificate, but it isn't clear to me if I need to grab the one from delicious or the site I'm trying to access.

+2  A: 

Well you have a missing quote on the first line:

$ch = curl_init('https://www.somesite.com/index.htm');

Apart from that, try

echo curl_error($ch);

before you close the handle.

Also you can show PHP errors (turn this off once you go live though):

error_reporting(E_ALL);
ini_set('display_errors', 1);
Greg
Sorry, the missing quote was just a typo here and I already have the error_reporting enabled.I just added the curl_error line, but sadly I get nothing as it still just sits there waiting.
fudgey
It can't sit there forever... if there was a DNS problem it could take 2 minutes to time out - have you left it that long?
Greg
LOL I don't have the attention span to wait 2 min :P... so I went AFK and came back and it was done but no data was being displayed. I haven't done a variable dump on $sFile, but I'm pretty sure it's empty
fudgey
Hmm that's very strange... try your var_dump($sFile) - you should definitely get something there *or* something from curl_error - they shouldn't both be empty
Greg
ok, now I'm getting this message: couldn't connect to hostbool(false)
fudgey
Greg
whew... well I claim being nieve on this part... The URL works from my broswer without difficulty. I'm using Windows XP and I think SSH is for Linux right?. The site ping was successful and I tried downloading Lynx but it didn't work for me =(
fudgey
and a +1 just for helping me thus far :)
fudgey
ty... hmmmmmm verrrry strange. Can you post the real URL? also try var_dump(file_get_contents('https://....'));
Greg
https://realmwar.warhammeronline.com/realmwar/ServerStatus.war, I'm trying to grab the server statuses
fudgey
I had the script working before when I was using `file_get_contents`
fudgey
+2  A: 

try something like

$sFile = curl_exec($ch);
$info = curl_getinfo($ch);

print_r($info);

that should contain some useful information.

Sabeen Malik
this is the output I get: couldn't connect to hostArray ( [url] => https://(truncated) [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0.023215 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => 0 [upload_content_length] => 0 [starttransfer_time] => 0 [redirect_time] => 0 )
fudgey
I truncated the URL above because of the 600 character limit... I did notice that oddly the script above works in XAMPP but not live on the host server... I'm wondering if there is a php setting I need to know about?
fudgey
i just think that this is either a firewall issue or a resolver config issue. put up a ticket with the hosting guys and tell them that you are getting that error with that domain. either they have a firewall blocking out requetsts or the dns confic is wrong.
Sabeen Malik
I think it is a firewall issue... oh well. Thanks!
fudgey