Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

PHP News Updater


ghost's Avatar
0 0

Okay, so, I would like to create a script that would allow people to update the news section of my site from within the site in an admin section. I'm aware that this would involve fopen() and fwrite() and all that, and I know how those work.

However, what if I don't want to write to the top/bottom of the file? Say I have a header and I want to insert the submitted news under information already in the file? Is there any way I can fwrite() to a point within the file rather then to the top or the bottom?

Thanks in advance.


ghost's Avatar
0 0

I wrote a thread on this yesturday, but I would use SQL, in one column I would use a date function to retrieve the date and time, and then add that data to a row, with the name of the news article in another, and then use a select statement with where to echo them in chronological order. But hang on, ill find my other fuller post that explains it with a bit more detail.


ghost's Avatar
0 0

Definitely use an SQL backend instead of flat files. But, what people often do wrong is they forget about caching.

They create a CMS which can post news, and such stuff. When someone loads the main page perhaps it does something like 20 SQL requests, but their last news post was 3 months ago. It's a total waste of resources. Ideally you'd use HTTP's Last-modified header to tell the client to use the cached version. That could save resources. If the site is actually very popular and perhaps you're posting a few news posts per week, maybe even one per day then you definitely need to find ways to save resources. In that case you should look into using memcached and the memcache extension for PHP and store the HTML for the front page in memory which saves you from those very expensive SQL commands.

Back to the first point though, definitely use SQL over files, it's much cleaner that way.