Writing and reading files with permissions

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
Rabloo
Forum Newbie
Posts: 4
Joined: Wed Apr 21, 2010 5:53 pm

Writing and reading files with permissions

Post by Rabloo »

Hey guys,

Is it possible to write a .txt file that has no public access (people can't view it), and then in another script read it (server-side reading/writing only)

?

Do I need to set file permissions when I create the file or something?

Thanks
User avatar
zeus1
Forum Newbie
Posts: 22
Joined: Tue May 18, 2010 10:45 pm
Location: /Under/The/AppleTree.png

Re: Writing and reading files with permissions

Post by zeus1 »

Yea, just make sure the folder you are writing to allows the webserver (www-data/apache) to write to it (make sure the webserver is the owner) and make sure that the folder does not allow global access. So something like this in the OS terminal: chmod g-rwx restricted_data_folder_for_world_name . If you also don't want people apart of your webserver group to be able to access file type: chmod go-rwx restricted_data_folder_for_world_name. If the files for some reason will have to be apart of the same folder you can use chmod function in php, keep in mind you have to use octals and not the friendly ascii codes. Refer to: http://us2.php.net/manual/en/function.chmod.php

Best Regards,
ZEUS
User avatar
zeus1
Forum Newbie
Posts: 22
Joined: Tue May 18, 2010 10:45 pm
Location: /Under/The/AppleTree.png

Re: Writing and reading files with permissions

Post by zeus1 »

BTW, if you go the PHP route you will change the permission for each file instead of the folder.

Best Regards,
ZEUS
Rabloo
Forum Newbie
Posts: 4
Joined: Wed Apr 21, 2010 5:53 pm

Re: Writing and reading files with permissions

Post by Rabloo »

Ok thanks I'll take a look into it.

oh and, just one more question..

Can users modify php session variables client-side? I'm pretty sure they are stored in the browser so couldn't the user potentially access/modify these variables?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Writing and reading files with permissions

Post by Benjamin »

Session data is stored on the server. The session id is sent to the browser. Clients can modify the session id, but not the contents of the session variables themselves. This is different from cookies of course, which are stored on the client machine.
Post Reply