Hello, I'm new here :) So hey everybody :thumbup:
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;)
Login
Started by Nightmare, Oct 25 2009 09:45 AM
7 replies to this topic
#1
Posted 25 October 2009 - 09:45 AM
|
|
|
#2
Posted 25 October 2009 - 10:36 AM
I'd recommend you to use sessions. Cookies should be used if you want the user to stay logged in longer than a few minutes.
In that case now, you just use
Preferable you should store the user ID and maybe the timestamp of the last action of the user (You may also store this in the database, it's up to you). With that you can always check if the last action is longer than 5 minutes ago.
In that case now, you just use
session_start();in the very first line of your script and then you can just assign values to the superglobal $_SESSION.
Preferable you should store the user ID and maybe the timestamp of the last action of the user (You may also store this in the database, it's up to you). With that you can always check if the last action is longer than 5 minutes ago.
#3
Posted 25 October 2009 - 10:37 AM
Ah right, Thankyou, So apart from
session_start();
do i have to use any other commands in other pages? such as
session_register(); ?
session_start();
do i have to use any other commands in other pages? such as
session_register(); ?
#4
Posted 25 October 2009 - 10:39 AM
You don't have to. The default values (as declared in the php.ini) should satisfy. :)
#5
Posted 25 October 2009 - 10:40 AM
Okay, thankyou, and last question,, do i call the session_start(); command on each page?
#6
Posted 25 October 2009 - 10:49 AM
Yes if I unsterstood you correctly.
Just have a look at this: php.net/manual/en/function.session-start.php
----
To be able to post links or images your post count must be 10 or greater. You currently have 5 posts.
Haha, great feature. :thumbdown:
Just have a look at this: php.net/manual/en/function.session-start.php
----
To be able to post links or images your post count must be 10 or greater. You currently have 5 posts.
Haha, great feature. :thumbdown:
#7
Posted 25 October 2009 - 11:15 AM
Yes, each time, you need to call that one. you can also have the user logged in for a longer time with the session, it's just to modify the session cookie :-)
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
#8
Posted 25 October 2009 - 11:16 AM
Ah right, thanks alot guys :)


Sign In
Create Account

Back to top









