Deleting, then refreshing page deletes next post as well

Dr. GBooky is here to help you with your guestbook problems ...
Post Reply
Judy
Posts: 7
Joined: Thu May 06, 2010 12:49 pm

Deleting, then refreshing page deletes next post as well

Post by Judy »

Script URL:
Version of script: 1.7
Hosting company: Hostmonster
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution: Delet*

Write your message below:

If I delete a post, then refresh the guestbook page with the small "message has been deleted" informational message that appears, I find that the next post is deleted as well. This is in Firefox 3.6.3.

I don't want to delete posts just by refreshing the page! Is there a way to control that behavior?
Judy
Posts: 7
Joined: Thu May 06, 2010 12:49 pm

Post by Judy »

Anyone?

Can someone at least confirm whether or not this behavior is replicated in other implementations?

1. Delete a post.

2. View the guestbook with "post has been deleted" message.

3. Refresh page.

Did you lose a post that you didn't expect to lose?
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Post by Henrie »

Hello Judy,

I just tested and can confirm your findings.
Furthermore, each time I refresh the page when the "post has been deleted" message is shown, I lose another message.
This is indeed an unwanted (and dangerous) behaviour and hopefully Klemen knows a way on how to change this behaviour.

Greetings,
Henrie
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
Judy
Posts: 7
Joined: Thu May 06, 2010 12:49 pm

Post by Judy »

Thank you, Henrie.
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

This is expected behaviour, because GBook posts don't have assigned IDs but get deleted by line numbers. So if you click on "a=delete&num=0" it will always delete the first line in the entries.txt file.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Judy
Posts: 7
Joined: Thu May 06, 2010 12:49 pm

Post by Judy »

But I'm not, Klemen. Henrie -- please explain?
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

GBook entries are stored in lines in the entreis.txt files. To delete an entry GBook actually deletes a line from the enires.txt file.

If you refresh the page your browser submits the command to delete the line you just deleted again to GBook so that line is deleted again.

Example: if your entires file has 5 lines:

AAAA
BBBB
CCCC
DDDD
EEEEE

You decide to delete one post (for exampl ethe 2nd post), GBook will delete line 2. The result will be:

AAAA
CCCC
DDDD
EEEE

Because you refresh the page and click the "Retry" button the browser again sends request to delete 2nd line, so the 2nd line is deleted again. The result is:

AAAA
DDDD
EEEE

If you refreshed again, it would again delete 2nd line:

AAAA
EEEE

and so on...
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Judy
Posts: 7
Joined: Thu May 06, 2010 12:49 pm

Post by Judy »

See http://www.dweephor.com/images/gberror.jpg .

There is absolutely nothing to indicate to the user that another post will be deleted if this display is refreshed. And then another ... and another ...
Judy
Posts: 7
Joined: Thu May 06, 2010 12:49 pm

Post by Judy »

If you could let me know what's generating the "Selected entry was successfully removed!" message, at least I could alter it to caution the user not to refresh the page.
Henrie
Posts: 1095
Joined: Sun Aug 14, 2005 8:57 pm

Post by Henrie »

@Klemen
Klemen wrote:This is expected behaviour, because GBook posts don't have assigned IDs but get deleted by line numbers. So if you click on "a=delete&num=0" it will always delete the first line in the entries.txt file.
Judy and I are saying that after the line in gbook.txt has been deleted the GBook shows the guestbook again with the message "Selected entry was successfully removed!". The address bar of the browser shows only the address http://www.mywebsite.com/gbook/gbook.php. So it is not clear that on refreshing the page it will send "a=delete&num=0" again.
I think Judy is right and that the current behaviour is not expected. I understand that the browser (in my case FF warns me that it resubmit previous data requests) will delete the data on resubmitting even though it is not indicated by the address bar. But still I think this is unwanted behaviour. Maybe you could introduce an extra step in the process of displaying the "Selected entry was successfully removed!" message so that on refreshing the page it will not delete another entry but just refreshes displaying the page.

@Judy
You can write the warning message yourself. Change in the file language.inc.php line

Code: Select all

$lang['t37']='Selected entry was successfully removed!';
to something like

Code: Select all

$lang['t37']='Selected entry was successfully removed!<br />Don\'t click refresh as it will delete another entry. <a href="gbook.php">Click on this text</a> or the \'View guestbook\' link to stop deleting messages.';
Greetings,
Henrie
I do not monitor the Gbook forums regularly anymore since I do not use the Gbook script myself anymore for a long time. But it helped me a lot in learning to understand php.
Judy
Posts: 7
Joined: Thu May 06, 2010 12:49 pm

Post by Judy »

"Maybe you could introduce an extra step in the process of displaying the "Selected entry was successfully removed!" message so that on refreshing the page it will not delete another entry but just refreshes displaying the page."

That would be perfect, Henrie. My browser doesn't warn me; I simply found one less post each time I would refresh the guestbook display. If there is an action tagged to the display of the "successfully removed" entry to end the deletion process, the issue would be solved.

In the meantime, I'll change the wording so the other moderators don't make that mistake. Thank you for the instructions.
Willem
Posts: 3
Joined: Sun Mar 28, 2010 1:17 pm

resfreh problem

Post by Willem »

Like Judy and Henrie i encountered the same problem.
The same happens also after adding a new entry.
After refresh every time the last added entry is added again

I would like to find a way to prevent this to prevent a polution of my guestbook.
Anyone suggestions?
Klemen
Site Admin
Posts: 10116
Joined: Fri Feb 11, 2005 4:04 pm

Post by Klemen »

This was introduced to skip a separate confirmation page (a "your post has been submitted/deleted ... click to continue" page).

But yes, I see why it's a problem and will include a check to just show the main guestbook page on refresh in future versions.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image You should follow me on Twitter here

Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...

Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Post Reply