How can I get the session ID in Laravel?

前端 未结 3 1485
礼貌的吻别
礼貌的吻别 2020-12-05 17:04

I want to get the id of the session in Laravel 4

In Laravel 3, it was a bit hacky, but possible with this code:

$session_id = Session::$instance->         


        
相关标签:
3条回答
  • 2020-12-05 17:38

    in laravel 5.5 first write this in your controller use Session; and inside your controller function write the following linesession()->getId();

    0 讨论(0)
  • 2020-12-05 17:39

    Depends on the version of Laravel:

    Laravel 3:

    $session_id = $_COOKIE["laravel_session"];
    

    Laravel 4.0:

    Just not versions 4.1 and above:

    $session_id = session_id(); //thanks Phill Sparks
    

    Laravel 4.1 (and onwards):

    $session_id = Session::getId();
    

    or

    $session_id = session()->getId()
    

    Laravel no longer uses the built-in PHP sessions directly, as a developer could choose to use various drivers to manage the sessions of visitors (docs for Laravel 4.2, Laravel 5.1, Laravel 5.2).

    Because of this, now we must use Laravel's Session facade or session() helper to get the ID of the session:

    0 讨论(0)
  • 2020-12-05 17:40

    Just had a little hunt for myself, because the above answers didn't work for me (Laravel 4.1)...

    Had to use this:

    Session::getId();
    
    0 讨论(0)
提交回复
热议问题