helraizer Posted January 5, 2008 Share Posted January 5, 2008 Hi Folks, I have a comment system on my website, but i don't use a database for it, so I don't really want to set one up. At the moment, on the comment submission if the user refreshes they can flood the comments page.. Using sessions, how would I stop the user posting more than 2 times in a minute (or one time in 30 seconds, if it's easier.. Hope that made sense, Sam Quote Link to comment https://forums.phpfreaks.com/topic/84561-sessions-to-stop-repetitive-form-submission/ Share on other sites More sharing options...
Ken2k7 Posted January 5, 2008 Share Posted January 5, 2008 So if you're not using a database, what are you using? Files? Quote Link to comment https://forums.phpfreaks.com/topic/84561-sessions-to-stop-repetitive-form-submission/#findComment-430858 Share on other sites More sharing options...
helraizer Posted January 5, 2008 Author Share Posted January 5, 2008 So if you're not using a database, what are you using? Files? I have a file called '.entries', which is written to each time a comment is posted. Each comment is seperated with ### so it explodes it at the ### and loads each comment into a div. If you want the code, just say. Although, there is a lot of it. Sam Quote Link to comment https://forums.phpfreaks.com/topic/84561-sessions-to-stop-repetitive-form-submission/#findComment-430859 Share on other sites More sharing options...
akitchin Posted January 5, 2008 Share Posted January 5, 2008 you can set a session variable with the current time. if the timestamp is less than 30 seconds old, don't show the form (also add a check into the posting process, because they may find a way around it): $_SESSION['antispamification'] = time(); if ((time() - $_SESSION['antispamification']) >= 30) { // show form } you'll need to follow all the usual session rules. for those, have a peek at a beginner's sessions tutorial. note that time() is a timestamp in seconds, so adjust the number appropriately if you wish to lengthen the "cooldown" phase. Quote Link to comment https://forums.phpfreaks.com/topic/84561-sessions-to-stop-repetitive-form-submission/#findComment-430861 Share on other sites More sharing options...
TheFilmGod Posted January 5, 2008 Share Posted January 5, 2008 It depends. If you have multiple things people comment on, then you can restrict them from commenting on the same thing twice. I'm sure going to a page and back would be a pain for the user so they wouldn't bother. You can do this with session without a problem. On another note, your method of the commenting system (with the file write each time) is very inefficient. Mysql is the answer - unless you have reason not to. It would be a lot faster and easier to sort. Quote Link to comment https://forums.phpfreaks.com/topic/84561-sessions-to-stop-repetitive-form-submission/#findComment-430950 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.