pass php session identifier between frontend and backend pages

I have a website based completely on php pages for frontend and backend and I use session to store some info. This way I just need to put session_start() on top of each page to have the session info available on page.
I would like to move to a different architecture and maintain backend on php while having frontend on html.

With this architecture how can I manage to have the session shared between the backend pages?
As per the documentation:

session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie

so I imagine I will have to pass somehow the session identifier back and forth between back and front end. Am I correct? If yes, how can I do it?

  • 2

    You already are passing the session identifier (probably in a cookie) from frontend to backend. Thats how sessions work in general, otherwise php couldn’t identify the session in a subsequent request. Maybe you should specify your question more precisely. What you want to achieve with that session in the frontend?

    – 




  • 2

    When you say a frontend based in HTML, do you mean like a separate website with something like React or Angular to manage the interaction? And the PHP just as a backend API which returns data as JSON or XML (for example) rather than building and outputting HTML content directly? In that architecture you would not normally use Session, you would design it so the backend is stateless and simply reponds to individual requests independently. We can’t answer this without knowing a bit more about your intent – it might be better suited to the PHP Discussions area

    – 




  • Please update the question to clarify what information you need where and what your problem with that is. Perhaps add a code example to your question? That would be great. If we can replicate your problem we may be able to solve it.

    – 

  • @ADyson that is exactly the point. I will dig a bit more about the stateless backend architecture

    – 

Leave a Comment