How do I limit sending data from a form?

Asked

Viewed 201 times

1

I want to prevent a user sending data more than 5 times a day; I have no way to use database would have to be written to a file txt.

  • Managed to solve the problem?

  • Not really, because I gave up on the idea... but it would be nice if I had a practical example using Cookies to control the number of times I could enter the page only it would not be very useful because it is easy to cheat and with the hint already passed here seems to be a little complicated; therefore the withdrawal!

  • There is no reliable way to do this, there is no way to know if the user is the same. You can try to control it however you want and nothing will work reliably, including and especially with cookies.

1 answer

2

Yes, it is possible to do this, it is not the most appropriate but it works. The simplest way to do this is to use the function file_put_contents()

file_put_contents($arquivo, $contador);

Then you will read the file with file_get_contents(), increment the counter and check if it has already exceeded 5 times:

$contador = intval(file_get_contents($arquivo));

Take a look at the documentation, there are some extra options in these functions that may be useful.

It is also possible to use other functions to manipulate the file more manually but I think that in this case it does not make sense. If you want to see something start with fopen(). On the side has all functions to handle files.

The file needs to have the proper permissions to be able to write to it. Which can create a security issue depending on where this file is.

Normally a separate folder is created that is outside the root of the hosting. So your script sees the file but it is not directly accessible by web.

If you don’t have access to a folder outside of the website normal (I would change hosting) and have no control over it is still possible to block external access using .htaccess.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.