writing to a file on a different server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sharonxph
Forum Newbie
Posts: 3
Joined: Mon Dec 02, 2002 3:23 pm

writing to a file on a different server

Post 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
Bugworm
Forum Newbie
Posts: 8
Joined: Fri Nov 29, 2002 7:54 pm

.... i think ...

Post 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... ;-)
sharonxph
Forum Newbie
Posts: 3
Joined: Mon Dec 02, 2002 3:23 pm

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

Post 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.
Bugworm
Forum Newbie
Posts: 8
Joined: Fri Nov 29, 2002 7:54 pm

... dumb question...

Post 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...
sharonxph
Forum Newbie
Posts: 3
Joined: Mon Dec 02, 2002 3:23 pm

yeah but...

Post 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
Bugworm
Forum Newbie
Posts: 8
Joined: Fri Nov 29, 2002 7:54 pm

... security...

Post 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.. ;-)
wahh346
Forum Newbie
Posts: 2
Joined: Mon Dec 02, 2002 4:55 pm
Location: Daytona Beach, FL

Post 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
User avatar
gyardleydn
Forum Commoner
Posts: 27
Joined: Tue Dec 03, 2002 8:27 am

Another Aproach

Post 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.
Post Reply