Abd Al Rahman
Abd Al Rahman

Reputation: 121

session reset after each request

i am building a frontend application with angular 7

i have build a middleware pure php inside angular project

that when angular need to send http request to backend, will send the request to php middleware and the php will process the request level and then send it to backend

the problem is i need to save value in php session on all request level but in each request the session is reset and any value that have it from previous session will be removed

the php middleware is a part of client not server so session must be unique for this client

what the problem and what i should to do

i haven't add any code cause i read and write to session normally nothing special

Upvotes: 2

Views: 253

Answers (1)

Henrymart
Henrymart

Reputation: 122

With angular 1, you can easily perform php session but Angular2 and above is written in such as to seperate front end entirely from backend. what you are looking for cannot easily be obtained. You should be looking at how to implement json webtoken and not php session. Generate json webtoken from php backend. Pass it as json and return it to the front end as per token.

You can choose to store the token in a html session or local storage and then use the token in a every request to php backend. At php back end, you will need to verify that the token has not been tampered since the token is securely signed digitally.

If for any reason the token is null or tampered discard the request and if not tampered accept the request and process your data.

They are many tutorials on building json web token in php. Google is your friend.

Just google building json web token in php

Upvotes: 1

Related Questions