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

amir5's avatar
Level 7

What is stored inside "decrypted" laravel_session cookie?

I wanted to know how laravel session(file driver), works. So I decoded the {appName}_session cookie(via .env key) to see whats inside.

It's consists of two parts(| separator), one of them is id of stored session(if driver is file, is file name, if it's cookie it's cookie name, and etc):

15f666e8581cd4587d81b729b35c9f64565c069e | m4VWFRNQ15zzTbNuLBlbbxRiGKBMNEgjFv5Ewzud

// if session driver is file 
// storage/framework/sessions/m4VWFRNQ15zzTbNuLBlbbxRiGKBMNEgjFv5Ewzud  

My question is, What is that first part means(used for)?

15f666e8581cd4587d81b729b35c9f64565c069e
0 likes
3 replies
AddWebContribution's avatar
Level 42

@amir5 The first part of the "decrypted" Laravel session cookie is the session ID. The session ID is a unique identifier that is generated for each user session and is used to associate a user's session data with their browser session.

When a user starts a new session, Laravel generates a unique session ID and stores it in the session cookie. The session ID is then used to retrieve the user's session data from the storage driver (in your case, the file driver) when the user makes subsequent requests to the application.

In the file driver, as you have mentioned, the session ID is used as the name of the file that stores the session data on the server. The file name is usually a hashed version of the session ID for security reasons.

Overall, the session ID plays a crucial role in Laravel's session management system as it allows the application to maintain stateful interactions with users across multiple requests.

1 like
amir5's avatar
Level 7

@saurabhd You mean first part is session id, and second part is hashed version of the first part?

77120bd's avatar

The first part is the SHA-1 hash of the cookie name with your encryption key.

See vendor/laravel/framework/src/Illuminate/Cookie/CookieValuePrefix.php at line 16: return hash_hmac('sha1', $cookieName.'v2', $key).'|';

Please or to participate in this conversation.