PHP, cURL, and HTTP POST example?

<?php // // A very simple PHP example that sends a HTTP POST to a remote site // $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,”http://www.example.com/tester.phtml”); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, “postvar1=value1&postvar2=value2&postvar3=value3”); // In real life you should use something like: // curl_setopt($ch, CURLOPT_POSTFIELDS, // http_build_query(array(‘postvar1’ => ‘value1’))); // Receive server response … curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $server_output = … Read more

How do I POST JSON data with cURL?

You need to set your content-type to application/json. But -d (or –data) sends the Content-Type application/x-www-form-urlencoded, which is not accepted on Spring’s side. Looking at the curl man page, I think you can use -H (or –header): -H “Content-Type: application/json” Full example: curl –header “Content-Type: application/json” \ –request POST \ –data ‘{“username”:”xyz”,”password”:”xyz”}’ \ http://localhost:3000/api/login (-H … Read more

We need a script to create a backup of all the files, database and email using third party Cpanel details in PHP

include “xmlapi.php”; $source_server_ip = “”; $cpanel_account = “”; // cPanel username $cpanel_password = ”; // cPanel password //Credentials for FTP remote site $ftphost = “”; // FTP host IP or domain name $ftpacct = “”; // FTP account $ftppass = “”; // FTP password $email_notify = ”; // Email address for backup notification $xmlapi = … Read more