Truemag

  • Categories
    • Tips And Tricks
    • Internet
    • PHP
    • Javascript
    • CSharp
    • SQL Server
    • Linux
  • Lastest Videos
  • Our Demos
  • About
  • Contact
  • Home
  • Write With Us
  • Job Request
Home PHP PHP CURL Post To HTTPS Website

PHP CURL Post To HTTPS Website

You’re probably familiar with using PHP cURL to load content from a website via its URL or send a web request (post/get) to consume a particular HTTPS API web service. However, you may have to face with an curl_error: “SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines: SSL3_GET_SERVER_CERTIFICATE: certificate verify failed” – curl_errno: 60

The problem will occur if the SSL certificate on remote site is invalid/expired/un-structed or the cURL is not configured to trust the server’s SSL certificate.

To fix the issue and be able to send request to HTTPS web service, you need to disable cURL verify SSL. Meaning that cURL will accept any SSL certificate. Honestly, this is not a good security practice but it can get your job done.

1. Simple PHP cURL post to HTTPS

The PHP script example below will send a post request to a HTTPS URL and display the return data.

<?php
	$url = "https://4rapiddev.com/demo/simple_post_https.php";
	$post_data = "name=Hoan&message=I'm from 4rapiddev.com";
 
	$response = post_https($url, $post_data);
	echo $response;
 
	function post_https($url, $post_data)
	{
		$ch = curl_init(); 
		curl_setopt($ch, CURLOPT_URL , $url ); 
		curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1); 
		curl_setopt($ch, CURLOPT_TIMEOUT , 60); 
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_USERAGENT , "" );
		curl_setopt($ch, CURLOPT_POST , 1); 
		curl_setopt($ch, CURLOPT_POSTFIELDS , $post_data ); 
 
		$xml_response = curl_exec($ch); 
 
		if (curl_errno($ch)) { 
			$error_message = curl_error($ch); 
			$error_no = curl_errno($ch);
 
			echo "error_message: " . $error_message . "<br>";
			echo "error_no: " . $error_no . "<br>";
		}
 
		curl_close($ch);
 
		return $xml_response;
	}	
?>

<?php $url = "https://4rapiddev.com/demo/simple_post_https.php"; $post_data = "name=Hoan&message=I'm from 4rapiddev.com"; $response = post_https($url, $post_data); echo $response; function post_https($url, $post_data) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL , $url ); curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1); curl_setopt($ch, CURLOPT_TIMEOUT , 60); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_USERAGENT , "" ); curl_setopt($ch, CURLOPT_POST , 1); curl_setopt($ch, CURLOPT_POSTFIELDS , $post_data ); $xml_response = curl_exec($ch); if (curl_errno($ch)) { $error_message = curl_error($ch); $error_no = curl_errno($ch); echo "error_message: " . $error_message . "<br>"; echo "error_no: " . $error_no . "<br>"; } curl_close($ch); return $xml_response; } ?>

2. Output:

Hello Hoan, you submitted a message: I'm from 4rapiddev.com<br>

Hello Hoan, you submitted a message: I'm from 4rapiddev.com<br>

Sep 27, 2011Hoan Huynh
Auto Delete Old IIS Logs, FTP Logs, SMTP Logs In WindowsFacebook Load User Profile Via Graph API And FQL Query
You Might Also Like:
  • ASP.NET Web Request POST/GET HTTPS Ignore Certificate Validation
  • PHP Get Webpage Content Using cURL
  • HTTP/ HTTPS Document, CGI-BIN And Access/ Error Logs On cPanel, Plesk And VirtualMin
  • ASP.NET Web Request Post/Get HTTP Example
  • How To Track Website With Multiple Google Analytisc Accounts
  • ASP.NET Cookie Domains HTTP HTTPS
  • Fatal error: Uncaught CurlException: 60: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed thrown
  • Setup Free SSL Certificate For Testing On Development Environment In Windows IIS 7
  • PHP auto post tweet to Twitter
  • PHP Parse Title Description Keywords From A Website
Hoan Huynh

Hoan Huynh is the founder and head of 4rapiddev.com. Reach him at [email protected]

9 years ago PHPcURL, curl_exec, CURLOPT_SSL_VERIFYHOST, CURLOPT_SSL_VERIFYPEER468
0
GooglePlus
0
Facebook
0
Twitter
0
Digg
0
Delicious
0
Stumbleupon
0
Linkedin
0
Pinterest
Most Viewed
PHP Download Image Or File From URL
21,956 views
Notepad Plus Plus Compare Plugin
How To Install Compare Text Plugin In Notepad Plus Plus
19,804 views
Microsoft SQL Server 2008 Attach Remove Log
Delete, Shrink, Eliminate Transaction Log .LDF File
15,629 views
JQuery Allow only numeric characters or only alphabet characters in textbox
13,136 views
C# Read Json From URL And Parse/Deserialize Json
9,595 views
4 Rapid Development is a central page that is targeted at newbie and professional programmers, database administrators, system admin, web masters and bloggers.
Recent Posts
  • Essay Writers
  • College Essay Writers – The Way to Earn Your Essay in Demand
  • Buy Research Papers – How to See Them at a Bargain Price
  • How to Write a Research Paper For Sale
  • Essay Writing – Some Useful Suggestions for Writing Urgent Essays
Categories
  • CSharp (45)
  • Facebook Graph API (19)
  • Google API (7)
  • Internet (87)
  • iPhone XCode (8)
  • Javascript (35)
  • Linux (28)
  • MySQL (16)
  • PHP (84)
  • Problem Issue Error (29)
  • Resources (32)
  • SQL Server (25)
  • Timeline (5)
  • Tips And Tricks (141)
  • Uncategorized (69)
Recommended
  • Custom Software Development Company
  • Online Useful Tools
  • Premium Themes
  • VPS
2014 © 4 Rapid Development