The problems was in SeoQuake Extension in Google Chrome. Once i've uninstaled it everything was working great. Do not know why, but uninstaling it got my problem fixed.
php uniqid() behaviour in session Chrome
-
30-09-2022 - |
Question
I am using sessions to store some informations about my images like this.
$imageId = uniqid();
$imageName = $tempName;
$viewImages[] = array(
'name' => $this->getDressImageUrl($tempName) . "?sid=" . time(),
'image' => $imageId,
'main_image' => $imgData['main_image']
);
print_r($imageId);
$this->saveImageNameToSession($imageId, $imageName, 'test');
Function saveImageNameToSession looks like this.
protected function saveImageNameToSession($imageId, $imageName, $text) {
print_r($imageId);
$sessionRegistry = $this->getServiceLocator()->get('session_registry');
$images = $sessionRegistry->offsetGet($this->getSessionKey('imgs'));
$images[$imageId]['image'] = $imageId;
$images[$imageId]['name'] = $imageName;
$images[$imageId]['text'] = $text;
$sessionRegistry->offsetSet($this->getSessionKey('imgs'), $images);
}
When i save the info in session a get this array
Array
(
[52de84947c4de] => Array
(
[image] => 52de84947c4de
[name] => vencanica-vencanica-1-large-a52de23cbaf45f.jpg
[text] => test
)
[52de84947c7f9] => Array
(
[image] => 52de84947c7f9
[name] => vencanica-vencanica-1-large-a52de7349674f2.jpg
[text] => test
)
)
values 52de84947c4de and 52de84947c7f9 matches with values created with uniqid(), but this is only in Firefox. In Chrome i get different values that do not match with passed uniqid(). I have busted my head with this and can not figure out why this works well in Firefox and doesnt work well in Chrome. What could be the problem?
Edit:
If i add the time()
on uniqid()
like this $imageId = uniqid() . time()
in firefox, the values for imageId
and image
in session are the same (52de8e69a94611390317161), but if is try it in Chrome imageId
and name
in session do not match (52de8ee79242a1390317287 vs 52de8eea5f37a1390317290) notice the last two digits, as if it is created in another time.
Solution