Php posting help

Hello unix.com

I want to use curl to post some logs to a remote server using curl.

$ch = curl_init("http://example.com/post/post.php");

curl_setopt($ch, CURLOPT_POST      ,1);
curl_setopt($ch, CURLOPT_POSTFIELDS    ,"FOUT=hash.gif&DATA=$message");
curl_setopt($ch, CURLOPT_HEADER      ,0);  // DO NOT RETURN HTTP HEADERS
curl_setopt($ch, CURLOPT_RETURNTRANSFER  ,1);  // RETURN THE CONTENTS OF THE CALL
$Rec_Data = curl_exec($ch);

What should post.php contain so can the script create the file and post the data into it?

Something like:

<?php
        if(isset($_POST['FOUT']))
        {
                $fp=fopen($_POST['FOUT']);
                fwrite($fp, $_POST['DATA']);
                fclose($fp);
        } ?>

I haven't tested this. I also haven't decoded however you translated the binary data of the message into ASCII text. It'll just dump it into the file as-is.

I'll test it right away and come back.

---------- Post updated at 06:11 PM ---------- Previous update was at 06:02 PM ----------

It doesnt work... The file isnt created on the remote host.

Any ideas?

Check the return values of all the calls. Tell us any error messages you get. We can't see your computer from here.

The web server needs permissions to write to that particular directory to write to it. If you haven't given it permissions, it doesn't have them.

chown :apache /path/to/dir/
chmod g+w /path/to/dir/

You should base64_encode() and then urlencode() the binary data to prevent data corruption.