Cookies stored using JavaScript being retrieved incorrectly with PHP

I have a web app built on Wordpress that stores a cookie using JavaScript:
document.cookie = "storedcookie="+cookie+"; path=/";
Later, it retrieves the cookie using PHP:
function prefill_fields ( $fields ) {
$fields['default'] = $_COOKIE["storedcookie"];
return $fields;
}
99% of the time this process works without any issues. However, for certain users, something strange happens:
If the cookie originally stored is: "~thisisacookie~thisisthesecondpart~thisisthefinalpart~"
Then, what is later retrieved will be: "~thisiy"
Basically, the first 5 or 6 characters, followed by a 'y'.
The users who usually experience this problem are often using iOS using mobile Safari. I have not been able to replicate this problem on any iOS device (iPhone 8 and onwards).
Does anyone have any clue what could be causing this issue? Many thanks.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: git was not found in your path, skipping source download
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.