0

So im using PHP and Curl trying to download a https weburl (from https://www.g2crowd.com) but its not working, here is the code i have so far one simple curl and the other more advanced curl , both are not working sadl. :(

// connect via SSL, but don't check cert
$ch=curl_init('https://www.g2crowd.com');
curl_setopt ($ch, CURLOPT_CAINFO, "cacert.pem");
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);  

$content = curl_exec($ch);

echo $content; // show target page
$ckfile = tempnam ("/tmp", 'cookiename');

$url='https://www.g2crowd.com/';
//$url='https://www.google.com';

$ch = curl_init();
curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $ckfile );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $ckfile ); 

curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$headers = [
'Host: www.g2crowd.com',
'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: en-US,en;q=0.5',
'Accept-Encoding: gzip, deflate'    
];
curl_setopt($ch, CURLOPT_CAINFO, 'C:\Users\ivan\Downloads\cacert.pem');

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, "https://www.g2crowd.com/users/c190d528-ab02-4cb5-8467-9362ceaec290");

curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$server_output = curl_exec ($ch);
if(curl_error($ch))
{
    echo curl_error($ch);
}
else {
    echo 'eureka!';
}

curl_close ($ch);

I tried to capture curl error so heres what the error is :

1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version

Please help im really at my wits end!

THank you !!

2
  • 2
    Where (and to what) is $i set? (See line 18.) Commented Oct 31, 2017 at 18:30
  • Hey cHao good point ! Thats a debugging leftover when i tried to loop through various ssl protocols , but even then when i set it or delete that parameter - it still returns an error. Commented Oct 31, 2017 at 19:22

2 Answers 2

1

Your openssl program is out of date. I've also seen this on the OSX version native. If you are on a Mac you will need to download a different openssl. Or, opening the SSL with 0 means you opened without SSL.

Sign up to request clarification or add additional context in comments.

1 Comment

Forbes thank you so much. I m using Zend Studio 13 IDE php debugger inside of Zend Studio, on a Windows 7 machine. So is this OpenSSL a program i need to install on windows or modify php.ini or something else? I also have Wamp installed , should i try running the script on Wamp local php server?
0

This should solve your problem:

$url='https://www.g2crowd.com/';

$ch = curl_init();

curl_setopt( $ch, CURLOPT_AUTOREFERER, TRUE );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE );

$server_output = curl_exec( $ch );

curl_close( $ch );

If that does not work, try:

$url='https://www.g2crowd.com/';
$server_output = file_get_contents( $url );

5 Comments

Thanx for help Ben! It may be just my PHP debugger but its not working , i assume you tried it and it worked for you ? Let me know please if you tested it and it worked.
@IvanSimic The problem is almost certainly with the way you have PHP (or at least its SSL libraries) setup up. But that’s hard to fix remotely. Generally the curl option I gave cures a lot of ills. Try the second option I provided. It may do the trick.
Solved i tried it on Wamp server and got a different curl error this time: "check ssl certificate" so googled for solution , tried on wamp server and it worked. Adding this code solved it: curl_setopt($ch, CURLOPT_CAINFO, 'C:\Users\ivan\Downloads\cacert.pem');
@IvanSimic Great!
hello,it results empty with your curl solutions,file_get_contents results Something goes wrong

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.