0

My backend is in php laravel 5.4, i want to use my session variables in my angular/ionic project the same way i use it in my blade files i.e by using $_SESSION['variable_name']

I have not found a way till now, the only way i have got till now is by calling an api and using this:

localStorage.setItem('sessionToken', response.sessionToken);

3
  • Sessions can't be used when using separating frontend and backend logic. You can use a cookie but then there is no point of angular/ionic project. You should instead store data in front end storage Commented Dec 1, 2020 at 13:43
  • developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage Commented Dec 1, 2020 at 13:46
  • 1
    As Jared mentioned, sessionStorage is the closest thing to a session variable. Just keep in mind that it's tab-exclusive (ie only applies to the current tab) and is removed once the tab and or the browser are closed. If you want to bind the variables to a user's login / logout routine-- I'm only guessing here-- then you'll have to set / remove the sessionStorage variables by yourself. Commented Dec 1, 2020 at 13:55

1 Answer 1

5

Since Angular is a front end framework (executed on the client side in the Browser), you cannot have direct access to the session.
PHP Session are for backend code (aka server side, executed on the server).
You must retrieve the value through an api call and store it on the front end (cookie, local storage etc)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.