Home › Forums › JavaScript › Allow user to click button once per day!
- This topic is empty.
-
AuthorPosts
-
August 10, 2014 at 6:04 am #178451David ReisParticipant
Hi people
Just wondering if someone could help me with this.I have a form that only want to show for people that clicked on the submit button more than 24 hours before. So if someone goes to the website and click on submit i will only allow them to submit again after 24 hours…
I know that this involves cookies and all so if someone could help me to get on the right track for this it would be great!!!
thanks in advance
dAugust 10, 2014 at 7:11 am #178457David ReisParticipantHi
Thanks SoronbeIm not using a database by the way. is just a php script that will stay live for a short period of time so i dont mind to have just a temporary solution for it.
d
August 10, 2014 at 8:17 am #178462David ReisParticipantCool
Do you know any solutions for this?August 10, 2014 at 8:55 am #178464AlenParticipantYou could use PHP’s file system to write a simple text file that can serve as a mini database.
In PHP you can read text files using
file($name_of_file);
which returns an array for you.So if the file contained IP addressed.
Let’s say
example.txt
contains these three lines:12.10.100 12.11.200 12.12.300
If you do
print_r( file( 'example.txt' ) );
You’ll get an array of:
Array( [0] => 12.10.100 [1] => 12.11.200 [2] => 12.12.300 )
Then before the form loads, you can check if IP is present in the array and handle it appropriately. If not, then write functionality that once the user submits form, add their IP to the file.
To check for value you could use PHP’s
in_array();
function.Hope that helps.
August 11, 2014 at 1:02 pm #178580noahgelmanParticipantI agree with Alen. Create a text file on the server and save the IP address of the people who submit the form and check the list when the user tries to submit.
You’ll also have to save the time the user submitted the form so if they’re over the 24 hour period it will reset the timerAugust 11, 2014 at 2:01 pm #178582__ParticipantKeep in mind that IP addresses almost never correspond 1:1 to a particular person. Hundreds of people might be assigned the same dynamic IP address by their ISP; one person might have a different IP address for each of a dozen consecutive requests. And that’s normal: not even considering someone who is trying to circumvent your checks.
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.