Jump to content

Cookies help


miligraf

Recommended Posts

I have installed a rating system at my site but i want to limit every person to 1 vote per file. What i have tried (with cookies) is that when a person votes, it creates a new cookie with that file id and if the cookie was made, then compare if the id's to see if the person is trying to vote again for the same file.

 

I had some reading of cookies but still cant make it...this if what i got so far, maybe im just confused lol:

 

<?php
function votar(){
//do something and then:
$i=descarga;
$viejaid=$id;
$viejadescarga=$i++;
setcookie("$viejadescarga", $viejaid);
}
if (!isset($_COOKIE['$viejadescarga'])){
setcookie("descarga", $id);
votar();
} else {
foreach ($_COOKIE['$viejadescarga'] as $viejadescarga => $viejaid){
	if ($viejaid==$id) {
?>
//Just one vote per file!
<?php
} else {
votar();
}}}
foreach ($_COOKIE as $viejadescarga => $viejaid){
print_r($_COOKIE);
}
?>

 

If there is a better way to have this done let me know, thanks!!!

Link to comment
https://forums.phpfreaks.com/topic/44666-cookies-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.