This is a discussion on CURL: Result on console and in PHP are different within the PHP Language forums, part of the PHP Programming Forums category; I have some problems with the curl. On the console I get the right response message but in PHP I ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I have some problems with the curl. On the console I get the right
response message but in PHP I see no difference between a valid and an invalid SSL Certificate. Curl command in PHP: $url = ' https://verisign.com'; $ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLE_OPERATION_TIMEOUTED, 10); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); $result = curl_exec ($ch); $info = curl_getinfo($ch); curl_close ($ch); print_r($info); Curl command on console: curl -I https://verisign.com Wrong SSL Certificate: curl -I https://verisign.com curl: (51) SSL: certificate subject name 'www.verisign.com' does not match target host name 'verisign.com' Array ( [url] => https://verisign.com [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [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 ) Correct SSL Certificate: curl -I https://www.verisign.com HTTP/1.1 200 OK Server: Netscape-Enterprise/4.1 Date: Wed, 31 Oct 2007 09:56:59 GMT Set-Cookie: v1st=4728516C0AACA713; path=/; expires=Wed, 19 Feb 2020 14:28:00 GMT; domain=.verisign.com Content-type: text/html Array ( [url] => https://www.verisign.com [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0 [namelookup_time] => 0 [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 ) |
|
|||
|
Paul van Brouwershaven wrote:
> I have some problems with the curl. On the console I get the right > response message but in PHP I see no difference between a valid and an > invalid SSL Certificate. > <snipped code> Yes, the certificate is set up for www.verisign.com, so when you try to go to verisign.com you get a name mismatch and it fails. FYI, Firefox shows a message indicating the mismatch when you try to https://verisign.com, also. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
On Oct 31, 11:21 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Yes, the certificate is set up forwww.verisign.com, so when you try to > go to verisign.com you get a name mismatch and it fails. > > FYI, Firefox shows a message indicating the mismatch when you try to https://verisign.com, also. Yes I know, thats the reason I try https://verisign.com but PHP is not giving me the error message/number in the [ssl_verify_result] value. I also tried: $url = ' https://www.verisign.com'; $ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLE_OPERATION_TIMEOUTED, 10); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); curl_setopt($ch, CURLOPT_CAINFO, '/usr/share/curl/cacert.pem'); curl_setopt($ch, CURLOPT_CAPATH, '/usr/share/curl/cacert.pem'); curl_setopt($ch, CURL_CA_BUNDLE, '/usr/share/curl/cacert.pem'); $result = curl_exec ($ch); $info = curl_getinfo($ch); curl_close ($ch); print_r($info); |
|
|||
|
Paul van Brouwershaven wrote:
> On Oct 31, 11:21 am, Jerry Stuckle <jstuck...@attglobal.net> wrote: >> Yes, the certificate is set up forwww.verisign.com, so when you try to >> go to verisign.com you get a name mismatch and it fails. >> >> FYI, Firefox shows a message indicating the mismatch when you try to https://verisign.com, also. > Yes I know, thats the reason I try https://verisign.com but PHP is not > giving me the error message/number in the [ssl_verify_result] value. > > I also tried: > > $url = ' https://www.verisign.com'; > > $ch = curl_init(); > curl_setopt($ch, CURLOPT_TIMEOUT, 10); > curl_setopt($ch, CURLE_OPERATION_TIMEOUTED, 10); > curl_setopt($ch, CURLOPT_URL, $url); > curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); > curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); > curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); > curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); > curl_setopt($ch, CURLOPT_CAINFO, '/usr/share/curl/cacert.pem'); > curl_setopt($ch, CURLOPT_CAPATH, '/usr/share/curl/cacert.pem'); > curl_setopt($ch, CURL_CA_BUNDLE, '/usr/share/curl/cacert.pem'); > > $result = curl_exec ($ch); > $info = curl_getinfo($ch); > curl_close ($ch); > > print_r($info); > > Sorry, I misunderstood your question. What do you get for the results from curl_init()? -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
Paul van Brouwershaven wrote:
> On Oct 31, 11:21 am, Jerry Stuckle <jstuck...@attglobal.net> wrote: >> Yes, the certificate is set up forwww.verisign.com, so when you try to >> go to verisign.com you get a name mismatch and it fails. >> >> FYI, Firefox shows a message indicating the mismatch when you try to https://verisign.com, also. > Yes I know, thats the reason I try https://verisign.com but PHP is not > giving me the error message/number in the [ssl_verify_result] value. > > I also tried: > > $url = ' https://www.verisign.com'; > > $ch = curl_init(); > curl_setopt($ch, CURLOPT_TIMEOUT, 10); > curl_setopt($ch, CURLE_OPERATION_TIMEOUTED, 10); > curl_setopt($ch, CURLOPT_URL, $url); > curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); > curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); > curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); > curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); > curl_setopt($ch, CURLOPT_CAINFO, '/usr/share/curl/cacert.pem'); > curl_setopt($ch, CURLOPT_CAPATH, '/usr/share/curl/cacert.pem'); > curl_setopt($ch, CURL_CA_BUNDLE, '/usr/share/curl/cacert.pem'); > > $result = curl_exec ($ch); > $info = curl_getinfo($ch); > curl_close ($ch); > > print_r($info); > > Also, IIRC, the results form the curl_init() should be false, and you should be able to get the error info from curl_errno() and/or curl_error(), not curl_getinfo(). -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
On Oct 31, 11:58 am, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> Sorry, I misunderstood your question. No problem > What do you get for the results from curl_init()? "$result = curl_exec ($ch);" results noting "$ch = curl_init();" results "Resource id #26" |
|
|||
|
Jerry Stuckle wrote:
> Paul van Brouwershaven wrote: >> On Oct 31, 11:21 am, Jerry Stuckle <jstuck...@attglobal.net> wrote: >>> Yes, the certificate is set up forwww.verisign.com, so when you try to >>> go to verisign.com you get a name mismatch and it fails. >>> >>> FYI, Firefox shows a message indicating the mismatch when you try to >>> https://verisign.com, also. >> Yes I know, thats the reason I try https://verisign.com but PHP is not >> giving me the error message/number in the [ssl_verify_result] value. >> >> I also tried: >> >> $url = ' https://www.verisign.com'; >> >> $ch = curl_init(); >> curl_setopt($ch, CURLOPT_TIMEOUT, 10); >> curl_setopt($ch, CURLE_OPERATION_TIMEOUTED, 10); >> curl_setopt($ch, CURLOPT_URL, $url); >> curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); >> curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); >> curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); >> curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); >> curl_setopt($ch, CURLOPT_CAINFO, '/usr/share/curl/cacert.pem'); >> curl_setopt($ch, CURLOPT_CAPATH, '/usr/share/curl/cacert.pem'); >> curl_setopt($ch, CURL_CA_BUNDLE, '/usr/share/curl/cacert.pem'); >> >> $result = curl_exec ($ch); >> $info = curl_getinfo($ch); >> curl_close ($ch); >> >> print_r($info); >> >> > > Also, IIRC, the results form the curl_init() should be false, and you > should be able to get the error info from curl_errno() and/or > curl_error(), not curl_getinfo(). > Sorry, I mean the results from curl_exec() should be false. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
Paul van Brouwershaven wrote:
> On Oct 31, 11:58 am, Jerry Stuckle <jstuck...@attglobal.net> wrote: >> Sorry, I misunderstood your question. > No problem > >> What do you get for the results from curl_init()? > "$result = curl_exec ($ch);" results noting > "$ch = curl_init();" results "Resource id #26" > > OK, so it initializes ok - but the execution fails. So the results should be in curl_error() and curl_errno(). I should know not to answer these things before my first pot of coffee! :-) -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
|
|||
|
On Wed, 31 Oct 2007 11:30:37 +0100, Paul van Brouwershaven
<p.vanbrouwershaven@gmail.com> wrote: > On Oct 31, 11:21 am, Jerry Stuckle <jstuck...@attglobal.net> wrote: >> Yes, the certificate is set up forwww.verisign.com, so when you try to >> go to verisign.com you get a name mismatch and it fails. >> >> FYI, Firefox shows a message indicating the mismatch when you try to >> https://verisign.com, also. > Yes I know, thats the reason I try https://verisign.com but PHP is not > giving me the error message/number in the [ssl_verify_result] value. > > I also tried: > > $url = ' https://www.verisign.com'; > > $ch = curl_init(); > curl_setopt($ch, CURLOPT_TIMEOUT, 10); > curl_setopt($ch, CURLE_OPERATION_TIMEOUTED, 10); > curl_setopt($ch, CURLOPT_URL, $url); > curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); > curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); > curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); > curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); > curl_setopt($ch, CURLOPT_CAINFO, '/usr/share/curl/cacert.pem'); > curl_setopt($ch, CURLOPT_CAPATH, '/usr/share/curl/cacert.pem'); > curl_setopt($ch, CURL_CA_BUNDLE, '/usr/share/curl/cacert.pem'); > > $result = curl_exec ($ch); > $info = curl_getinfo($ch); > curl_close ($ch); > > print_r($info); <?php //notice it doesn't start with a space... $url = 'https://www.verisign.com'; $ch = curl_init(); curl_setopt($ch, CURLOPT_TIMEOUT, 10); curl_setopt($ch, CURLE_OPERATION_TIMEOUTED, 10); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1); $result = curl_exec ($ch); if(!$result) echo curl_error($ch); $info = curl_getinfo($ch); curl_close ($ch); print_r($info); ?> -- Rik Wasmus |
|
|||
|
As saw the space problem just before you post, but this still doesn't
solve the problem that there is no value in the ssl_verify_result result. If the SSL Certificate is wrong or right it always returns 0! I can check the result of the curl_exec to see if the certificate is valid, but this doen't tell me what the problem is. |