Learning PHP
Posted by Jim at June 9th, 2004
Though I do know enough about PHP to put together a mildly complex registration form for a conference, I still have much to learn.
Right now I’m in the process of rewriting GRACE’s website such that anyone in the organization can change and edit text on the site. As a result, I have to learn how to allow PHP to edit files. The goal is to allow people the ability to edit only those parts of the document that I trust them with (text) and leave the rest alone.
This means that I’m in the process of investigating how PHP reads in and writes out files. Here’s one amusing thing I’ve learned: fopen (the command for opening/writing files) apparently does not lock. This means that if two people edit the same file and attempt to write the file at the same time, fopen will attempt to write both versions at once, creating a file full of utter gibberish.
So… it looks like I may have to write my own locking mechanism. That or allow only one person to edit files at a time.
Originally, I was going to let MoveableType handle this, but, the number of authors makes that more expensive than I think we want to bother with.
I would seriously look into Textpattern for that need.
Ed Heil
btw: http://us3.php.net/manual/en/function.flock.php
Ed Heil
Why try opening files. Why not have the info for each section stored in a database, use user authentication and only let some people edit certain areas and then have online forms for each area and edit that way. I use php for my blog and it works great.
joel
Joel:
I’m thinking that your general approach is right about that. That’s what I’ll be doing for most of the site.
There will be a few basically static files that I’d like people to be able to edit, but don’t really fit into the templates that I’ll be creating.
Ed:
The link looks useful. Funny what doesn’t get mentioned in tutorials. I ran across the problem with fopen, but not the solution. Textpattern does look tempting, but reinventing the wheel may fit organization better. I’m still in the early stages of things, however, so I might change my mind on that.
Jim Zoetewey