Forum Moderators: coopster

Message Too Old, No Replies

Writing to a file on a remote server without FTP

         

benry

11:53 pm on Aug 31, 2005 (gmt 0)

10+ Year Member



I am new to PHP and have a small problem and wondered if anyone could help. We have three sign-up areas for our site, two are hosted on our server, a third on another site for very good reasons.
I want a logfile of when people subscribe. The logfile is hosted on our server.
Writing to the logfile is easy for the two scripts running on our server.
My original plan for the remote site had simply been to open an FTP connection and write it that way, and that worked a treat - until I got the remote site to test it on their servers. They do not allow outbound FTP.
This may be the world's stupidest question, but is there another way of passing the results of the sign up (which is just a date, an email address and to which list they have subscribed) to the logfile on our server without using FTP? Is there someway I could use $_POST for example?
I have found this forum to be incredibly useful and have learned a huge amount from it so far - so many thanks indeed.
Many thanks

Ben

coopster

12:17 am on Sep 1, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, benry. Happy to have you come into the forum and participate/interact!

There are a number of ways to accomplish the task and yes, POST is one of them. You could assemble your own POST headers and fire them off. The following is an example that should get you started in the right direction:

if (isset($_POST['Submit'])) { 
$date = urlencode [php.net]($_POST['date']);
$email = urlencode [php.net]($_POST['email']);
$list = urlencode [php.net]($_POST['list']);
$fp = fsockopen [php.net]('www.example.com', 80, $errno, $errstr, 30);
if (!$fp) {
// handle it somehow if you receive an error;
// maybe write to a text file or log file on the remote server.
} else {
$out = "POST /mylogs/mylogscript.php HTTP/1.1\r\n";
$out .= "Host: www.example.com\r\n";
$out .= "Content-Type: application/x-www-form-urlencoded\r\n";
$out .= "Content-Length: " . strlen("date=$date&email=$email&list=$list") . "\r\n";
$out .= "Connection: close\r\n\r\n";
$out .= "date=$date&email=$email&list=$list";
fwrite($fp, $out);
$response = '';
while (!feof($fp)) {
$response .= fgets($fp, 128);
}
fclose($fp);
}
}

benry

11:35 pm on Sep 1, 2005 (gmt 0)

10+ Year Member



Pure genius - I am in awe.

Works a treat straight out of the box. I can't thank you enough.

Ben