A problem with my simple comment system

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
tehhparadox
Forum Newbie
Posts: 18
Joined: Thu Oct 01, 2009 11:55 am

A problem with my simple comment system

Post by tehhparadox »

Hi guys

I made this simple comment system, where people could just write in their name and comment and leave a message that everyone can see.

I've got a form set up with the fields name and comment, and I have a text file to store all the past comments (not database!).

Anyway, my program opens this txt file with fopen() append, and writes to it with fputs(). The only problem is, whenever people refresh the page after they left the comment, the browser sends the typed info again to the form, and the comment appear again. Can you do something to prevent this? I'll appreciate any help.

thanks
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: A problem with my simple comment system

Post by Darhazer »

You have to redirect the user with header('Location: ...') after he puts the comment, in order to dispatch the POST data, and to allow them to refresh without reposting.
tehhparadox
Forum Newbie
Posts: 18
Joined: Thu Oct 01, 2009 11:55 am

Re: A problem with my simple comment system

Post by tehhparadox »

Thanks Darhazer! you solved my problem.
Post Reply