How to limit the sending of data of a form?

1

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

    
asked by anonymous 06.12.2014 / 01:37

1 answer

2

Yes, it is possible to do this, it is not the most suitable but it works. The simplest way to do this is to use the 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));

Read 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 in this case it does not make sense. If you want to see something, start by fopen() . On the side you have all the functions to manipulate files.

The file must have the appropriate permissions to be able to write to it. This can create a security problem 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 do not have access to a folder outside the normal site (I would change hosting) and have no control over it, you can still block external access using .htaccess .

    
06.12.2014 / 02:08