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

angelorigo's avatar

Reading cakePHp session into Laravel and Authenticating into Laravel

Hi

I am redirecting from cakePHP 2.5 to Laravel 5.1 app and need to share the authentication maintaining the same user logged in into both cakePHP and Laravel.

The session is stored on Memcached.

How can i read the cakePHP session and authenticate into Laravel ?

I redirect with this hacking at cakePHP Webroot/index.php using the PHP native header function, can i pass aditional needed data using header?:

App::uses('LaravelController','Controller');
$Laravel = new LaravelController();
if( $Laravel->faq() != "" ){
      header("Location: http://www.laravelapp.com/faq");
} else {
        App::uses('Dispatcher', 'Routing');
        $Dispatcher = new Dispatcher();
        $Dispatcher->dispatch(
                new CakeRequest(),
                new CakeResponse()
        );
}

Into laravel {{ dd( Request::session() ) }} just shows the Laravel session and {{ dd( Auth::check() ) }} returns false .

0 likes
8 replies
bobbybouwmann's avatar

I'm not sure if this is even possible. Laravel creates the session using a hash which is based on the app key. So when Laravel tries to read the hash from cakePHP it won't be able to decrypt it to the correct data..

I have heard others about doing this as well, but never saw anyone succeed..

jlrdw's avatar

Have you tried a regular session for this? You will probably have to do some custom coding in authorization.

angelorigo's avatar

I can see the CAKEPHP session id maybe will try $session_id = Session::getId(); to start. Will try to read $_SESSION .

angelorigo's avatar

It is not possible to read $_SESSION inside a controller : $cakeSession = $_SESSION['CAKEPHP']; gives the an error exception cannot read _SESSION variable

jlrdw's avatar

Temporarily use regular sessions in cake and laravel.

angelorigo's avatar

Can i use Laravel events to see if the request is coming from a know cakephp route ? and fire the laravel auth ?

angelorigo's avatar

If i var_dump($_SESSION) inside a blade template or a controller gives me the error: Undefined variable: _SESSION

HEre is what i try and the output: <?php var_dump($_SESSION); ?> {{ dd( \Session::get('user') ) }} null {{ dd( \Session::all() ) }} a encripted token {{ dd( Auth::check() ) }} false

romanosk8's avatar

Hola, me encuentro en el mismo problema, consulta..... Lograste compartir sesión entre las dos App Cacke y Laravel?, saludos y gracias.

Please or to participate in this conversation.