Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nikocraft's avatar

how to get session values

I save a session value like this

Session::push('image.hash.'.$imageHash, $imageHash);

later I want to check on all sessions that are image.hash.* since I don't know at later time the value of $imageHash

I tried this

if(Session::has('image.hash.*'))

but ofcourse it does not work. How can I loop through all these session values if I dont know the last part

image.hash.djn6ago
image.hash.fJtbru
image.hash.ai12de
0 likes
3 replies
ehtasham's avatar
ehtasham
Best Answer
Level 2

Session::all() will give you all session data in array.

$session = Session::all();

$mySession = [];

forearch ($session as $value) {
    if (strpos($value, 'image.hash') !== false)  {
        $mySession[] = $value;
    }
}

$mySession will contain 'image.hash';

nikocraft's avatar

@ehtasham

I have now actually tried your example and I get this error

strpos() expects parameter 1 to be string, array given

any ideas what I can do about it?

Please or to participate in this conversation.