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->session['id'];
But I can't work it out in Laravel 4... referencing the Session::$instance
object throws errors:
Access to undeclared static property: Illuminate\Support\Facades\Session::$instance
have tried:
$session_id = Session::get('id');
but to no avail.. any ideas?
Your application's session configuration file is stored at config/session. php . Be sure to review the options available to you in this file. By default, Laravel is configured to use the file session driver, which will work well for many applications.
Laravel ships with several great drivers out of the box: file - sessions will be stored in storage/framework/sessions . cookie - sessions will be stored in secure, encrypted cookies. database - sessions will be stored in a database used by your application.
PHP - session_id() Function Sessions or session handling is a way to make the data available across various pages of a web application. The session_id() function is used to set or retrieve a custom id to the current.
Depends on the version of Laravel:
$session_id = $_COOKIE["laravel_session"];
Just not versions 4.1 and above:
$session_id = session_id(); //thanks Phill Sparks
$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:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With