I\'m working on setting up credit card processing and needed to use a workaround for CURL. The following code worked fine when I was using the test server (which wasn\'t cal
Try the following.
function getSslPage($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_REFERER, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
Note: This disables SSL verification, meaning the security offered by HTTPS is lost. Only use this code for testing / local development, never on the internet or other public-facing networks. If this code works, it means the SSL certificate isn't trusted or can't be verified, which you should look into fixing as a separate issue.
$url= 'https://example.com';
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$response = file_get_contents($url, false, stream_context_create($arrContextOptions));
This will allow you to get the content from the url whether it is a HTTPS
HTTPS is supported starting from PHP 4.3.0, if you have compiled in support for OpenSSL.
Also, make sure the target server has a valid certificate, the firewall allows outbound connections and allow_url_fopen
in php.ini is set to true.
TO CHECK IF AN URL IS UP OR NOT
The code in your question can be rewritten as to a working version:
function send($packet=NULL, $url) {
// Do whatever you wanted to do with $packet
// The below two lines of code will let you know if https url is up or not
$command = 'curl -k '.$url;
return exec($command, $output, $retValue);
}
This is probably due to your target server not having a valid SSL certificate.
I was stuck with non functional https on IIS. Solved with:
file_get_contents('https.. ) wouldn't load.
edit php.ini with:
curl.cainfo = "C:\Program Files\PHP\v7.3\extras\ssl\cacert.pem" openssl.cafile="C:\Program Files\PHP\v7.3\extras\ssl\cacert.pem"
finally!