last day (15 days later) » 

11:47 AM
0
Q: How can I set PHP cookie to user pc so that user can't apply again within 24 hours?

creativeartbdAfter successfully submitting the form I am setting the submission time using PHP cookie. If the user again submits the form then I am checking if the time is past 24 hours or not. If it's not passed 24 hours then I am showing an error message. So for that in the Chrome browser, it's working ...

 
Are the users anonymous or logged in? If it's an important rule, then you shouldn't use cookies since the user can simply clear all cookies and submit the form over and over. Cookies should never be used to store any kind of important data.
 
What is the error message you see?
 
there is not login system so the user is anonymous. No problem if user delete cookie but I want to prevent the user to submit again from his PC within 24 hours.
 
Does not compute "No problem if user delete cookie" !== "but I want to prevent the user to submit again from his PC within 24 hours"
 
@TomRevell updated. Sorry typo.
@RiggsFolly Simple things- I don't want that user can submit again within 24 hours.
 
11:47 AM
Why don't you just create a cookie that expires after 24 hours. Then you only need to check if the cookie exists at all. No need to store the time in the cookie and calculate the diff.
 
Or log the IP/ MAC (or login) server side, that way nobody can delete their cookie...
 
@MagnusEriksson is that cookie is available on multiple browsers after set for the first time?
 
Cookies are deleteable and amendable Take some credentials (email/password) and store in DB with a last_applied_at field. if last_applied_at is less than 24h, throw an exception
 
is that cookie is available on multiple browsers after set for the first time NO
 
“is that cookie is available on multiple browsers after set for the first time?” - of course not. The cookie is stored by the browser, it doesn’t magically make its way into a completely different browser.
 
11:47 AM
@creyD - How would you get the clients MAC using PHP (or JS, for that matter)?
 
@MagnusEriksson Yes I was wondering that too. :) Very interested in the answer
 
So there is no way with PHP cookie to prevent the user within 24 hours in the same pc??
 
@MagnusEriksson stackoverflow.com/a/1420402/7454177 this could help you for example.
 
@creyD - Did you actually read that answer? "But what if the client isn't on a LAN? - Well, you're out of luck unless you can have the client volunteer that information and transmit via other means.". It the server and the client are on the same LAN, you can check it through the network, but online is a no go
 
So there is no way with PHP cookie to prevent the user within 24 hours in the same pc YES, but only if they know nothing about how browser and the web work. A cookie is not a sensible solution to this problem you are going to have to come up with another mechanism
 
11:47 AM
Yeah, I read that and it adds to my comment: you can't get the MAC address, but the IP address. I know it's not as convenient, but it's a start. TBH I thought that the HTTP protocol sends the MAC too...
 
Thanks All but it will be better if is there any way :(
 
@creyD - Never use IP as an identifier.
 
Yeah I know, but what else could you use in this case server side? If there is no login...
 
I see @creyD, Thanks anyway.
 
@creyD - Sometimes it's better to totally rethink what you're doing instead of doing it poorly. IP's for example, they can change (dynamic IP's), they can be shared (everyone behind a router usually all have the same public IP). And if you're using a mobile or laptop, you will get new IP's everytime you connect to a new wifi
 
11:47 AM
@MagnusEriksson I know that most people have dynamic IP's and I personally would rely on more stable solutions for my projects, but I thought it would help to think about server side checks and not client side ones...
 

last day (15 days later) »