0

I am developing a game website where multiple different games could be active at a given time. At the moment a lobby area lists games that a user is able to enter and upon doing so a session variable is created which is how the site knows what to display.

This isn't ideal as the session variable prevents one user having multiple games open on different tabs. Additionally if a user wanted to return via browsing history to a certain game it would instead take them to the game which the session variable is currently pointing or if one isn't set redirect to lobby.

So far my URL would only show something like this mysite.com/game/home.php Looking at other sites it would be more useful both for bookmarking as well as for clarity displaying something more like mysite.com/game-gameID/home etc

I've been looking a little at URL slugs but I can't see any signs that variables could be passed this way, it also seems like a potential weakness in the security of site as well.

Hoping someone might be able to recommend a sensible way to achieve useful URLs for this project. Or if slugs would do the job where to get further information.

  • Of course you can pass variables this way, why do you think you can't? Start with URLs like `/game.php?room=42`. Is that clear, do you know how this works? Then using `/room/42` instead is just prettifying that URL, it still contains the same basic information. – deceze Aug 04 '20 at 13:47
  • Very happy with GET and POST. So I would need to start keeping the gameID in the URL as a GET variable and not a session variable. 'Prettyfying' would then be a something to implement after using rewriting as pointed out in that linked question. Cheers – PickleBranston Aug 04 '20 at 14:21

1 Answers1

0

Resolving parameterized urls is usually done by what is called a router. If you're using plain php, without a framework, i advise you to look into writing one. You'll then be able to use urls as you like, without being constrained by your folder structure and without that ugly little *.php at the end.