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

Akeno's avatar

Change session data with a link

Hi,

I'm making a game and I got different objects (planets, spaceships, ...) with different interfaces and data. To display the correct interface with the correct data (e.g. resources owned by this object) I need to have the object's id.

Currently, I solve this problem by putting the id into the URL, like this:

planet/5/overview // typeOfInterface/objectId/page

Of course, I check if the id belongs to the currently logged in user.

But I think that's not the best, cleanest solution. I'd rather prefer using sessions (or is there an even better way, what do you think?). But there's one big problem that comes with it.

I would save the current objectId inside the session. But I need to change the object id when clicking on a link (e.g. to go from planet A to planet B). I could create a connecting route (e.g. /objectId/change/{$objectId}) that changes the id and redirects somewhere else. But this connecting route doesn't know where to redirect. I don't know how to tell it that. Anyways, this would be a bad solution as well I think. It makes everything more complicated and indirect.

Do you ave any ideas how to be able to change data in a session when clicking a link?

0 likes
1 reply
pmall's avatar
pmall
Best Answer
Level 56

But I think that's not the best, cleanest solution.

This is way clearer than what you try to do. I strongly advice you to stay with well structured urls. Managing state with sessions should be used the less you possibly can : it quickly become a mess.

1 like

Please or to participate in this conversation.