Can I handover sessions from Laravel to my simple MVC?

Kbir Mhrjn

I just want to know if I am able to hand over session variables from Laravel to my custom code. What I mean is: I want to handle log-in through Laravel and pass it to my profile section which is not in Laravel. Most of the routes are handled by a .htaccess file. The goal is to just login with Laravel auth and save that to $_SESSION['user'] var and redirect to /profile. Somehow I don't get that. The session name is the same in both, in Laravel's session.php's cookie name and my custom code's constant. Is there any other factor I should consider ?

Okay here's the code:

namespace Services\Session;

class OldSessionAuth
{
    protected $auth;
    function __construct()
    {
        $this->auth = \Auth::user();
    }
    public function setSession()
    {
        $_SESSION['user'] = $this->auth->toArray();
        $_SESSION['auth'] = 'TRUE';
        return true;
    }
    public function destroy()
    {
       session_destroy();
       session_unset();
    }
}

So, this is sort of my Session services, which is initialized only if it passes the Auth from the controller, Now I think I don't need to do that. so I skiped it, Basic Stuffs (Auth::Check()) really. So, I'd just do this in my login method.

$old = new Services\Session\OldSessionAuth();
$old->setSession();
return Redirect::to('/');

The home page is controlled by my custom made MVC and I want to grab the session, which in this case I can't. It shows Array(). There is no session manipulation when retrieving the session.

jeteon

Laravel already has a pretty good session abstraction so I don't think you needed to use session_start(), $_SESSION etc directly. Sharing an session across two applications is a bit tricky. If you are tied to using the cookie approach, then you have to make sure that the session driver in use is the cookie one. You would also need to ensure that the restrictions on the cookie aren't such that your other application isn't being sent them by the user's browser.

By default, PHP will use a file cookie driver. In this case, what you would have to do in your other application is to read the "PHPSESSID" cookie, set the session ID using session_id() to this and only then would you have access to the session data using the $_SESSION variable in the other application.

This is all pretty hacky though. I would recommend that if you need to share sessions that you make use of a database session driver instead. This way, you are able to share arbitrary session data across applications using a standard interface. In this case, you would just read the "laravel_session" cookie instead to be able to look up the session in the database. There would be many hidden pitfalls if you then wanted to also modify this data from the other application as well though.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can I handover sessions from Laravel to my simple MVC?

From Dev

How can I keep my SSH sessions from freezing?

From Dev

laravel 5.2 how can i create simple search in my application

From Dev

How can I best handle sessions in my RestController within Spring?

From Dev

How can I export or import my WinSCP sessions?

From Dev

How can I force tmux to sort my sessions alphabetically?

From Dev

Why is my javascript function not being invoked for simple MVC tutorial? Why can't I debug either?

From Dev

Why is my javascript function not being invoked for simple MVC tutorial? Why can't I debug either?

From Dev

How can I access my Laravel app from another PC?

From Dev

I can't retrieve my data from request AJAX in Laravel

From Dev

How Can i send the email from the MVC4 to my gmail without using my password?

From Dev

Google Analytics: I can't see any sessions for my site but I see real-time data

From Dev

Using Sessions (or otherwise) what can I do to make my page remember the variables when I go back to it?

From Dev

Laravel 5: how do I tell Sessions.php to use my .env database connection?

From Dev

How do I import show_simple_view from enaml.stdlib.sessions?

From Dev

How do I import show_simple_view from enaml.stdlib.sessions?

From Dev

How can I return an MVC error message from user registration to my client browser

From Dev

How can I read from a network path on my server using asp.net mvc application

From Dev

How can I use ASP.NET MVC (or Core) to detect and redirect cookieless sessions?

From Dev

My Laravel 5.2.10 Sessions wont persist

From Dev

Can I find out the number of open sessions for my web aplication (IIS 7 and higher) programmatically

From Dev

Is there a way I can build a project using Laravel, but keep the core files separate from my site's files?

From Dev

How can I output my webcam directly to a simple HTML page?

From Dev

MVC: Can I clear ViewBag from Javascript?

From Dev

laravel and multi-sessions from the same browser

From Dev

Ruby on Rails: How can I get all sessions data from Redis on server side?

From Dev

How can I list the WM manager sessions available from the command line?

From Dev

How can I list the WM manager sessions available from the command line?

From Dev

How can I launch multiple screen sessions from a single bash script?

Related Related

  1. 1

    Can I handover sessions from Laravel to my simple MVC?

  2. 2

    How can I keep my SSH sessions from freezing?

  3. 3

    laravel 5.2 how can i create simple search in my application

  4. 4

    How can I best handle sessions in my RestController within Spring?

  5. 5

    How can I export or import my WinSCP sessions?

  6. 6

    How can I force tmux to sort my sessions alphabetically?

  7. 7

    Why is my javascript function not being invoked for simple MVC tutorial? Why can't I debug either?

  8. 8

    Why is my javascript function not being invoked for simple MVC tutorial? Why can't I debug either?

  9. 9

    How can I access my Laravel app from another PC?

  10. 10

    I can't retrieve my data from request AJAX in Laravel

  11. 11

    How Can i send the email from the MVC4 to my gmail without using my password?

  12. 12

    Google Analytics: I can't see any sessions for my site but I see real-time data

  13. 13

    Using Sessions (or otherwise) what can I do to make my page remember the variables when I go back to it?

  14. 14

    Laravel 5: how do I tell Sessions.php to use my .env database connection?

  15. 15

    How do I import show_simple_view from enaml.stdlib.sessions?

  16. 16

    How do I import show_simple_view from enaml.stdlib.sessions?

  17. 17

    How can I return an MVC error message from user registration to my client browser

  18. 18

    How can I read from a network path on my server using asp.net mvc application

  19. 19

    How can I use ASP.NET MVC (or Core) to detect and redirect cookieless sessions?

  20. 20

    My Laravel 5.2.10 Sessions wont persist

  21. 21

    Can I find out the number of open sessions for my web aplication (IIS 7 and higher) programmatically

  22. 22

    Is there a way I can build a project using Laravel, but keep the core files separate from my site's files?

  23. 23

    How can I output my webcam directly to a simple HTML page?

  24. 24

    MVC: Can I clear ViewBag from Javascript?

  25. 25

    laravel and multi-sessions from the same browser

  26. 26

    Ruby on Rails: How can I get all sessions data from Redis on server side?

  27. 27

    How can I list the WM manager sessions available from the command line?

  28. 28

    How can I list the WM manager sessions available from the command line?

  29. 29

    How can I launch multiple screen sessions from a single bash script?

HotTag

Archive