ElectricRain,
I'm not sure that sessions will do what you want as securely as you want it. Of the top of my head I can think of two alternatives:
Option One
(You have probably seen this on other sites)
On your form page, create an image of some distorted text and display it. Then, as part of the form entry procedure, the user would have to enter the text displayed into a textbox. The nice thing being that it is very difficult for a simple web app (i.e. other sites) to perform OCR on distorted text, hence preventing them from using your form.
How do you verify the text without sending the text to the client also? Send a hash (md5 for example) of the generated text to the browser in a hidden field. When the form is submitted, hash the users entry and compared with the hash sent to the browser. They should match.
I am quite sure that there are php utils out there to generate distorted text. Can anyone suggest one?
Option Two
(less secure than one, but less hassle for the user)
Have a submission_tokens table in your DB. When the form page is requested, use a hidden field to store a token id, which specifies a row on the submission_tokens table.
The submission_tokens table would have the columns:
- tokenid (preferably a pseudo random string or int)
- creationDate (the tokens creation date)
- requestersIP
When the form is submitted, check the tokenid's creation date in the database. If the date has been exceeded, then throw them an error.
Option two - part B
Of course, another website could simply grab a form page from your site and extract the token id. So, you could also monitor the IP of each client that requests a token (i.e. the form page) using the requestersIP field. If you have handed out more than a few tokens to them in the last x minutes/hours then you should present them with an error.
Well, what do you think? 🙂