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

DavidBuchukuri's avatar

how does laravel's default authentication works under the hood?

I knew that, default laravel's authentication is basically an authentication with sessions, but when i wanted to dive deeper, I couldn't find any material which would answer my questions. Laravel docs focuses mostly on implementation, and other blog posts dig into oop side of auth. My questions are for example, why is session generated for standard visitor of website, which is not logged in or anything. Also when i looked into browser cookies, session id was different from what is generated inside storage/framework/sessions folder. maybe there is happening some type of hashing or encryption in between?. Typical Session generated inside sessions folder looks like this

a:4:{s:6:"_token";s:40:"ZtAEKxUlA5PyMAr0q1SjltLGJ8IjnWC7DNsfclyY";s:9:"_previous";a:1:{s:3:"url";s:21:"http://127.0.0.1:8000";}s:6:"_flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}s:50:"login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d";i:1;}

what a:4 s:6 s:40 s:9 refer to? and where is a user id? Answers or Resources that would clarify my confusion, would be greatly appreciated.

0 likes
6 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

What you are looking at is serialized. So to read it you would need to run the unserialize() function on it. Also session data is encrypted using the APP_KEY. It can be decrypted using laravel, but laravel does so for session data automatically

DavidBuchukuri's avatar

@Sinnbeck also how can i decrypt and take a look at the session id? when i do this Crypt::decryptString('session_id_copy_from_a_browser'), I get an error The payload is invalid

Please or to participate in this conversation.