Page 1 of 1

writing to a file on a different server

Posted: Mon Dec 02, 2002 3:23 pm
by sharonxph
This is what I am trying to do:
I have a form that works with form tags post and action(action is calling the php script)
I want the info from the form that the visitor fills out, written to a text file which resides on a different server (different than where the php script resides) How can I do this?
I've already changed the permissions so that the text file is writable.
I've also tried fopen, fsockopen. How do I handle what I am trying to accomplish?

THanks for any help.
Sharon

.... i think ...

Posted: Mon Dec 02, 2002 4:19 pm
by Bugworm
it would work pretty easy, i dont know, i never did that on an other server than mine, but it might work...

just define the file were it should be writte to absolute...

Code: Select all

<?php 

/* define the filehandle*/

$filehandle="http://www.yourdomain.com/file.dat";

/* open the filehandle, and write the data in it */

	$fp=fopen($filehandle, "w");
	flock($fp,2);
	fputs($fp, $data, strlen($data));
                flock($fp,3);
	fclose($fp);
?>
I hope that helps you, but i am not shure, cause i dont use 2 servers to write on them... ;-)

re: well... works but isn't writing anything to file

Posted: Mon Dec 02, 2002 4:52 pm
by sharonxph
Thanks for replying.

I defined the $data variable and the page is loaded just fine without errors but it doesn't write anything to the text file.

... dumb question...

Posted: Mon Dec 02, 2002 4:55 pm
by Bugworm
... isnt it possible to run a php script on that server ???

i mean, just do take a php script on that server as the action of the form ???
that would be much easier, and it will work shurely...

yeah but...

Posted: Mon Dec 02, 2002 5:22 pm
by sharonxph
The form needs to be on one server but the contents that it collects needs to be on another. I don't want the people who have access to the script and server to be able to access the collected data. :-D :D

... security...

Posted: Mon Dec 02, 2002 7:00 pm
by Bugworm
.... i think, that if you realy want to let the script change the file on the other server, you have to set the security options for that file so low, that it would be easier to get as if you let it on the original server, and try to block unwanted access...
but as i said.. i only run one server... and dont know how it would be with 2.. ;-)

Posted: Mon Dec 02, 2002 8:47 pm
by wahh346
One possible solution (guru's feel free to check this) may exist for using one server if your running linux (maybe other OS's also)

Give the user/group that PHP/Apache is running as permission to your text file. (this will allow your script to write to it)

Make your admins part of a new group that has permissions to the scripts only and not the text file.

If I'm not completely off base here, this would allow you to view the text file as a superuser, your script to write to the file, and your admins access to only the .php files and NOT the text file.

I'm new to this but this method may be worth checking in to.

-wahh346

Another Aproach

Posted: Tue Dec 03, 2002 8:27 am
by gyardleydn
You might want to try a different approach. Save the information on the server your visitor is look at in a directory only the other computer is allowed look at. The name should be unique for each visitor.

Have the computer run a periodic task (Cron in Linux) that examines the visiting computer for new files and saves any changes in the format you desire. Have the original files deleted based on date daily or hourly, as you desire, based on date.