restricting file access

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
brandan
Forum Commoner
Posts: 37
Joined: Sat Jul 24, 2004 6:39 pm
Location: fort smith, ar

restricting file access

Post by brandan »

i have a script that opens a flat file for reading, then places information read from the flat file into a database. i'm anticipating that more than one person will view the page at any given moment, and that possibly this script will be run at or around the same time, resulting in the same file being opened and duplicate entries being placed into the database.

does anybody know of any way to approach this, or if it's not even an issue? perhaps php closes off access to files it's currently working with. i'm not sure.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. set a flag in the database
  2. lock the file for exclusive access.
those are about the only things I know of. Making the file require a username and password to even open can help. As well as putting it in a "safe" place.

If you restricted the calling of the script to say, user x, y, and z.. that'd also limit the chances.. but locking the data file and setting a flag in the database are probably the most "secure" ways of locking.
brandan
Forum Commoner
Posts: 37
Joined: Sat Jul 24, 2004 6:39 pm
Location: fort smith, ar

Post by brandan »

well here's an example of what i'm doing, because i might not have been very clear in my original post. i have the music i've recently listened to logged into a flat file using a plugin for foobar2000, then parsed by another script, and placed into a database to be read by other scripts to be presented on a website. the flat file is read after the index.php is loaded to sort of 'automate' the parsing of the flat file, so i won't have to do it manually. if that's not clear, i'll post some of the script.
Last edited by brandan on Fri Apr 01, 2005 6:18 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

my reply works with that.
brandan
Forum Commoner
Posts: 37
Joined: Sat Jul 24, 2004 6:39 pm
Location: fort smith, ar

Post by brandan »

alright, i'll look some of that up.
brandan
Forum Commoner
Posts: 37
Joined: Sat Jul 24, 2004 6:39 pm
Location: fort smith, ar

Post by brandan »

oh, and afterwards the file is removed using unlink().

i think flock() is what i'm looking for. i'll mess with it later.
Post Reply