Get the last modified date of a remote file

You could probably do something like this using curl_getinfo(): <?php $curl = curl_init(‘http://www.example.com/filename.txt’); //don’t fetch the actual page, you only want headers curl_setopt($curl, CURLOPT_NOBODY, true); //stop it from outputting stuff to stdout curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); // attempt to retrieve the modification date curl_setopt($curl, CURLOPT_FILETIME, true); $result = curl_exec($curl); if ($result === false) { die (curl_error($curl)); … Read more

Save cURL content result into a string in C++

You will have to use CURLOPT_WRITEFUNCTION to set a callback for writing. I can’t test to compile this right now, but the function should look something close to; static std::string readBuffer; static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) { size_t realsize = size * nmemb; readBuffer.append(contents, realsize); return realsize; } Then call … Read more

Send JSON POST request with PHP

You can use CURL for this purpose see the example code: $url = “your url”; $content = json_encode(“your data to be sent”); $curl = curl_init($url); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_HTTPHEADER, array(“Content-type: application/json”)); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, $content); $json_response = curl_exec($curl); $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ( $status != 201 ) { … Read more

CURL import character encoding problem

Like Jon Skeet pointed it’s difficult to understand your situation, however if you have access only to final text, you can try to use iconv for changing text encoding. I.e. $text = iconv(“Windows-1252″,”UTF-8”,$text); I’ve had similar issue time ago (with Italian language and special chars) and I’ve solved it in this way. Try different combination … Read more

FTP upload file to distant server with CURL and PHP uploads a blank file

After 2 days of banging my head against the keyboard.. finally i did it.. Here is how: <?php if (isset($_POST[‘Submit’])) { if (!empty($_FILES[‘upload’][‘name’])) { $ch = curl_init(); $localfile = $_FILES[‘upload’][‘tmp_name’]; $fp = fopen($localfile, ‘r’); curl_setopt($ch, CURLOPT_URL, ‘ftp://domain.com/’.$_FILES[‘upload’][‘name’]); curl_setopt($ch, CURLOPT_USERPWD, “user:pass”); curl_setopt($ch, CURLOPT_UPLOAD, 1); curl_setopt($ch, CURLOPT_INFILE, $fp); curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile)); curl_exec ($ch); $error_no = curl_errno($ch); curl_close … Read more

Install curl with openssl

Try this when you configure the libcurl ./configure –with-ssl –with-libssl-prefix=/usr/local/ssl /usr/local/ssl is where openssl contains header files and library /usr/local/ssl/ ├── bin ├── certs ├── include ├── lib ├── man ├── misc ├── openssl.cnf └── private

Warning: file_get_contents: failed to open stream: Redirection limit reached, aborting

Had a similar problem today. I was using CURL and it wasn’t returning my any error. Tested with file_get_contents() and I got… failed to open stream: Redirection limit reached, aborting in Made a few searches and I’v ended with this function that works on my case… function getPage ($url) { $useragent=”Mozilla/5.0 (Macintosh; Intel Mac OS … Read more

Escaping CURL @ symbol with PHP

Use http_build_query() on your data-array first before passing it to curl_setopt(), that will lead to it sending the form as application/x-www-form-encoded instead of multipart/form-data (and thus the @ is not interpreted). Also why do you really care about the @ in an email-address? It only matters if the @ is the first character, not somewhere … Read more

PHP CURL Using POST Raw JSON Data

If you wanna use Content-type: application/json and raw data, seem your data should be in json format $ch = curl_init(); $headers = [ ‘x-api-key: XXXXXX’, ‘Content-Type: application/json’ ]; $postData = [ ‘data1’ => ‘value1’, ‘data2’ => ‘value2’ ]; curl_setopt($ch, CURLOPT_URL,”XXXXXX”); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData)); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); $result = curl_exec … Read more