PHP CURL & HTTPS

Quick fix, add this in your options: curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false) Now you have no idea what host you’re actually connecting to, because cURL will not verify the certificate in any way. Hope you enjoy man-in-the-middle attacks! Or just add it to your current function: /** * Get a web file (HTML, XHTML, XML, image, etc.) from … Read more

curl: (60) SSL certificate problem: unable to get local issuer certificate

Relating to ‘SSL certificate problem: unable to get local issuer certificate’ error. It is important to note that this applies to the system sending the CURL request, and NOT the server receiving the request. Download the latest cacert.pem from https://curl.se/ca/cacert.pem Add the ‘–cacert /path/to/cacert.pem’ option to the curl command to tell curl where the local … Read more

how to upload file using curl with PHP [closed]

Use: if (function_exists(‘curl_file_create’)) { // php 5.5+ $cFile = curl_file_create($file_name_with_full_path); } else { // $cFile=”@” . realpath($file_name_with_full_path); } $post = array(‘extra_info’ => ‘123456’,’file_contents’=> $cFile); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$target_url); curl_setopt($ch, CURLOPT_POST,1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post); $result=curl_exec ($ch); curl_close ($ch); You can also refer: http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/ Important hint for PHP 5.5+: Now we should use https://wiki.php.net/rfc/curl-file-upload but if … Read more

How to POST JSON Data With PHP cURL?

You are POSTing the json incorrectly — but even if it were correct, you would not be able to test using print_r($_POST) (read why here). Instead, on your second page, you can nab the incoming request using file_get_contents(“php://input”), which will contain the POSTed json. To view the received data in a more readable format, try … Read more

Can PHP cURL retrieve response headers AND body in a single request?

One solution to this was posted in the PHP documentation comments: http://www.php.net/manual/en/function.curl-exec.php#80442 Code example: $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 1); // … $response = curl_exec($ch); // Then, after your curl_exec call: $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); Warning: As noted in the comments below, this … Read more

How do I make a request using HTTP basic authentication with PHP curl?

You want this: curl_setopt($ch, CURLOPT_USERPWD, $username . “:” . $password); Zend has a REST client and zend_http_client and I’m sure PEAR has some sort of wrapper. But its easy enough to do on your own. So the entire request might look something like this: $ch = curl_init($host); curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/xml’, $additionalHeaders)); curl_setopt($ch, CURLOPT_HEADER, 1); … Read more

PHP – Debugging Curl

You can enable the CURLOPT_VERBOSE option and log that information to a (temporary) CURLOPT_STDERR: // CURLOPT_VERBOSE: TRUE to output verbose information. // Writes output to STDERR, // -or- the file specified using CURLOPT_STDERR. curl_setopt($curlHandle, CURLOPT_VERBOSE, true); $streamVerboseHandle = fopen(‘php://temp’, ‘w+’); curl_setopt($curlHandle, CURLOPT_STDERR, $streamVerboseHandle); You can then read it after curl has done the request: $result … Read more