[Solved] How to prevent visitors to use a feature more than once
Posted: Sun Jul 12, 2009 4:03 pm
Hello there,
I am currently working on a rating plug-in. I know there are already some pretty decent solutions available, I just wanted to see if I can make it
It works pretty decent, however, I have one last riddle to be solved. How do I prevent a user from rating an item twice? I see several options:
1) Temporarily store IP in DB
2) Store in cookie
3) Store in Session
The downside I see with IP, is that you might exclude several users from the option to vote (e.g. corporate networks). I though of something like th following to get the IP (this piece of code is actually not made by myself, just for clarification). However, I do not think that this is rock solid for this purpose (or a little too solid
.
Generally, the item to be rated (the IDs) is stored in the session so that I only pass the actual score via URL. This way, I need a cookie anyway, so I can assign the session from the server with the visitor (if I understood the concept correctly). I though to place the already rated items in the cookie and then check the cookie. This way I can make sure, I prevent the single visitor from rating a again, not the whole company.
The rating thing is a fun option. It is no critical part to the site, but I just like to prevent people from clicking a hundred times in a row.
So I thought, I could as well place an array in the session containing the items as the third option. When people have to open and close their browser, they'll surely stop jerking around.
Triggering the rating URL without being on the site doesn't work, as the rating function relies on ID data being in the session. If that is not available, it won't perform any DB action.
So how would you go about this?
Any feedback appreciated.
Best
Nils
I am currently working on a rating plug-in. I know there are already some pretty decent solutions available, I just wanted to see if I can make it

It works pretty decent, however, I have one last riddle to be solved. How do I prevent a user from rating an item twice? I see several options:
1) Temporarily store IP in DB
2) Store in cookie
3) Store in Session
The downside I see with IP, is that you might exclude several users from the option to vote (e.g. corporate networks). I though of something like th following to get the IP (this piece of code is actually not made by myself, just for clarification). However, I do not think that this is rock solid for this purpose (or a little too solid

Code: Select all
function rating_VisitorIP()
{
if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
$TheIp=$_SERVER['HTTP_X_FORWARDED_FOR'];
else $TheIp=$_SERVER['REMOTE_ADDR'];
return trim($TheIp);
}
The rating thing is a fun option. It is no critical part to the site, but I just like to prevent people from clicking a hundred times in a row.
So I thought, I could as well place an array in the session containing the items as the third option. When people have to open and close their browser, they'll surely stop jerking around.
Triggering the rating URL without being on the site doesn't work, as the rating function relies on ID data being in the session. If that is not available, it won't perform any DB action.
So how would you go about this?
Any feedback appreciated.
Best
Nils