Jump to content

Recommended Posts

Hello, I'm new here  8) So Hey Everybody! :P

 

I'm also quite new to php, so I need some advice, if anybody is willing to give it.

 

I'm trying to make a text based game in php, but i'm unsure as to how to make the login system.

 

What I have right now, is something that, when you log in, you pass your username and password into the next page, the login page. So it checks that the username exists, and then that the hashed password is the same as the hashed password stored in the MySQL Database. Now, im not sure how to ensure that the player STAYS logged in.

 

My plan is so that if the player is inactive for 5 minutes, they will be automatically logged out.

 

My first instinct would be to use $_SESSION, but im not sure exactly how its used, and i was told by someone that it is ridiulous to use $_SESSION for a game and that i should use $_COOKIE.

 

Can anybody give me a little advice on what to do, and if it is $_SESSION, could you explain how to register sessions and use them, not in high detail of course, that would take up too much of your time, but just a quick overview if possible.

 

Thanks In Advance, Nightmare  ;D

Link to comment
https://forums.phpfreaks.com/topic/178961-login/
Share on other sites

  • 3 weeks later...

some use $_SESSION, some use $_COOKIE

(I use $_SESSION)

 

session_start() //has to be the first line of your php code if you need sessions
$_SESSION['example'] = 'this is an example'; // asigns the string to a session
print $_SESSION['example']; // prints This is an example
$example = $_SESSION['example']; //asigns the value of the session to a variable

Link to comment
https://forums.phpfreaks.com/topic/178961-login/#findComment-954256
Share on other sites

If you are going to use cookies, be careful, because cookies are trivial to change. For a log in, I would suggest sessions, but for their login expiring, you could use a cookie (and obviously just refresh the cookie every time they go to a new page, or do something)

Link to comment
https://forums.phpfreaks.com/topic/178961-login/#findComment-954258
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.