dink87522 Posted December 31, 2009 Share Posted December 31, 2009 This should be simple, but I can't get it to work now. $score = $_COOKIE["score"]; if(isset($_COOKIE["hsPrev"])){ $hsPrevious = $_COOKIE["hsPrev"]; $hsPreviousSort = explode(",", $hsPrevious, 6); }else{ $hsRecord = $score; setcookie("hsPrev", $hsRecord); } the above doesn't work and the code I had which was mostly working is gone now. $score will equal say 5. This score is to be stored in the cookie hsPrev. Say the next score = 2. Should be stored/apended to the end of the cookie also i.e. "5,2" I only want their to be 5 scores in the cookie (i.e. say "4,2,12,3,9"), the 5 latest, so the older scores should be removed and this is predominantly where I am having trouble. Can someone help me with this? Link to comment https://forums.phpfreaks.com/topic/186754-cookies-and-simple-data-manipulation/ Share on other sites More sharing options...
RussellReal Posted December 31, 2009 Share Posted December 31, 2009 don't use cookies for this.. its so easy to spoof a score.. use a session.. and sessions r so much easier.. session_start(); if (isset($_SESSION['hsPrev'])) { $_SESSION['hsPrev'][] = $newScoreToBeAppended } else { $_SESSION['hsPrev'] = array(); $_SESSION['hsPrev'][] = $newScore; } that will build $_SESSION['hsPrev'] as such: hsPrev ( [0] = 4, [1] = 6, [2] = 2, [3] = 5 ) and so on and so forth.. then when you want to look thru the scores just call it like you would have after you explode by ',' for example $_SESSION['hsPrev'][0] will equal 4 in the given example. Link to comment https://forums.phpfreaks.com/topic/186754-cookies-and-simple-data-manipulation/#findComment-986218 Share on other sites More sharing options...
dink87522 Posted January 1, 2010 Author Share Posted January 1, 2010 Thanks, as usual I was trying to over-complicate it. Link to comment https://forums.phpfreaks.com/topic/186754-cookies-and-simple-data-manipulation/#findComment-986642 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.