Failing to connect through HTTPS and cURL at PHP - php

I am trying to connect to an API using cURL and https and I don't get it work.
It work perfectly with http but when i change it to https in the $url variable, it takes more than 30 seconds to execute and finally it shows false as a result.
This is the function:
$url = 'https://api.xxxxxxx.com/api.php?user=xxxx&pass=xxxx';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
If I debug with this:
debug(curl_init($url));
I get:
resource
Any idea which could be the cause?

It ended up to be that the website was trying to access didn't allow secure connections.

Related

What something wrong with my CURL script, I m passing addon ip

i want to use CURL with addon ip which is added on my server So i am using below script for simple CURL pass.
<?php
function get_html($url,$ip) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_INTERFACE, $ip);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FAILONERROR, 0);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$ip="173.214.xxx.198";
$l = get_html("http://www.checkip.com/",$ip);
echo $l;
?>
This script running fine on other server . Please give me solution of this problem
If it works fine on another server then there's nothing wrong in this script. Do you have curl installed on the server that's failing?

curl https SITE with proxy

I want to curl https SITE with proxy, but I failed.
curl -x IP:PROT 'https://SITE'
It returns:
curl: (56) Proxy CONNECT aborted
Is there anyway that meet my need?
THX
P.S: I am using PHP (curl) also, and I want to do this with PHP.
HERE is my code:
$ip = "IP:PORT";
$url = "https://SITE";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_PROXY, $ip);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
var_dump($output);

How to connect to a secure (https) proxy with curl and php?

Modern browsers support HTTPS proxies that can be connected to via a PAC file (see https://www.igvita.com/2012/06/25/spdy-and-secure-proxy-support-in-google-chrome/ if you're not familiar).
I'm trying to replicate the same thing and connect to such a proxy via php CURL, but I'm simply getting a blank response, no headers or content.
My code is as follows:
$url = "http://checkip.dyndns.com";
$proxy = "proxy.domain.com:443";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL , 1);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, 'test:test');
curl_setopt($ch, CURLOPT_PROXYTYPE, "CURLPROXY_HTTP");
$response = curl_exec($ch);
curl_close($ch);
echo $response;
Any ideas?
If anyone is interested, the solution to this is to use spdycat instead of curl: https://github.com/tatsuhiro-t/spdylay
There's no support for connecting to a proxy with HTTPS with curl yet. There is a work-in-progress branch in git though: https://github.com/bagder/curl/tree/HTTPS-proxy
We will appreciate help to get that in shape to merge.

Wikipedia and cURL with PHP

I'm trying to load information from Wikipedia with cURL and PHP, but it's not working as intended.
See my code :
$url = "http://en.wikipedia.org/w/api.php?action=opensearch&format=xml&limit=1&search=stackoverflow";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'USERAGENT');
$result = curl_exec($ch);
curl_close($ch);
//return $result;
var_dump($result);
It doesn't return anything. However, if you load the address in your browser, it works!
So I'm wondering what should I change in order to execute this cURL request well.
Thank you folks !
The request is redirecting to https. So either reference the https uri instead or set CURLOPT_FOLLOWLOCATION to true:
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

PHP cURL request to same server returning false

I've searched high and low for the answer to this question but cant find anything...
We've got a single server and on it we've got a PHP service with an API.
We've recently written an PHP app which interacts with the API. When it goes live the API and the app will be on the same server.
However, when they are on the same server the cURL requests from the app to the API always return false. I'm sure this must be something to do with the way that the request is being routed by the server. Is there any way to make this work properly?
$url = 'http://api.some_address_on_the_same_server.com';
$postdata = array(...);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch); // $result is always false when on the same server for some reason
curl_close($ch);
Must be related to locking session situations. Try this way.
<?php
$url = 'http://api.some_address_on_the_same_server.com';
$postdata = array(...);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
session_write_close();
$result = curl_exec($ch); // $result is always false when on the same server for some reason
curl_close($ch);
session_start();
?>
EDIT :
Have you added an exception in your windows host file ?
/windows/system32/drivers/etc/hosts
like
127.0.0.1 yourdomain.com
For more information. Check out this

Categories