Jump to content

Recommended Posts

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.