Nexus Zero Posted August 1, 2007 Share Posted August 1, 2007 My aim with this code is to prevent multiple votes on a single comment. I'm attempting to do this by adding an arrayed cookie that has a unique entry added each time a user votes. However, when I echo the following code <?php $judgement = $_GET['j']; $commentid = $_GET['cid']; setcookie("cookie[$commentid]", $commentid); ?> I get this error message: Notice: Undefined index: cookie[$commentid] in /home/fhlinux166/t/trivipedia.org/user/htdocs/judge.php on line 46 $commentid is a number, such as 1, 18 etc. Does php have rules against this or am I doing it wrong? Thanks. Link to comment https://forums.phpfreaks.com/topic/62870-solved-naming-cookies-with-variables/ Share on other sites More sharing options...
wildteen88 Posted August 1, 2007 Share Posted August 1, 2007 Is line46 this line? setcookie("cookie[$commentid]", $commentid); That should be fine To fetch the cookie you'd use this variable: $_COOKIE['cookie'][$commentid]; Not like this: $_COOKIE['cookie[$commentid]']; Link to comment https://forums.phpfreaks.com/topic/62870-solved-naming-cookies-with-variables/#findComment-312972 Share on other sites More sharing options...
Nexus Zero Posted August 1, 2007 Author Share Posted August 1, 2007 Mate that's fantastic. I've since applied that syntax to an isset and the code works perfectly. Many, many thanks! Link to comment https://forums.phpfreaks.com/topic/62870-solved-naming-cookies-with-variables/#findComment-313021 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.