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

Thirdwrist's avatar

why can't i name a session with a number? rather than a string

I created this session to increment when ever a new session is declared. but it keeps read the if false because i saved the session name with an int instead of the key being using the name of the int which is 25, it starts from 0. but when i save the session name with a string, the session saves and works perfectly.

 {
        $id = $request->route('id');
        $session_id = $id;
        
       //  $ba = 4;
       //  $foo = "four";
       //  $za = $session_id + $foo;
       // dd($za);
        
        if(Session()->exists($session_id))
        {
            return $next($request);    
        }


        else{
            
            $var = new post;
            $var->viewcount_session($session_id);
            $results = post::select('page_views')->find($id);
            $results= ++$results->page_views;
            $results= DB::table('posts')->where('id', $id)->update(['page_views' => $results]);

            return $next($request);
        }
public function viewcount_session($session_id){
        $var = $session_id;
        return  $value = session([$var =>'car']);
        redirect('/articles/{id}');

    }
0 likes
5 replies
crnkovic's avatar

@Cronix I don't think Laravel uses PHP's native session engine but rather it's own implementation based on Symfony's Cookie Jar. But still, the name of the session is required to be a string.

Thirdwrist's avatar

Yeah @Cronix was right. What i finally did was

$session_id = "twenty" . $id;

that worked..

Cronix's avatar

I'm fairly confident Symphony is just using a custom php session handler, which is what allows you to use native (file), database, redis, etc for session storage, but all are using php's session mechanisms under the hood with a custom handler.

crnkovic's avatar

https://laravel.com/docs/5.0/releases#laravel-5.0

"With this release, we're also introducing an entirely new session engine. Similar to the routing improvements, the new session layer is leaner and faster. We are no longer using Symfony's (and therefore PHP's) session handling facilities, and are using a custom solution that is simpler and easier to maintain."

"Native PHP sessions output cookies straight to the headers and there is no way to change that. It breaks the entire request/response wrapping that Laravel has." - Taylor

I believe it's built on native PHP cookies rather than sessions.

Please or to participate in this conversation.