Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Allow user to click button once per day!

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #178451
    David Reis
    Participant

    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
    d

    #178457
    David Reis
    Participant

    Hi
    Thanks Soronbe

    Im 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

    #178462
    David Reis
    Participant

    Cool
    Do you know any solutions for this?

    #178464
    Alen
    Participant

    You 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.

    #178580
    noahgelman
    Participant

    I 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 timer

    #178582
    __
    Participant

    Keep 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.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.