Jump to content

Login

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1
Nightmare

Nightmare

    Newbie

  • Members
  • Pip
  • 5 posts
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;)

#2
kwm

kwm

    Newbie

  • Members
  • PipPip
  • 11 posts
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
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
Nightmare

Nightmare

    Newbie

  • Members
  • Pip
  • 5 posts
Ah right, Thankyou, So apart from
session_start();

do i have to use any other commands in other pages? such as

session_register(); ?

#4
kwm

kwm

    Newbie

  • Members
  • PipPip
  • 11 posts
You don't have to. The default values (as declared in the php.ini) should satisfy. :)

#5
Nightmare

Nightmare

    Newbie

  • Members
  • Pip
  • 5 posts
Okay, thankyou, and last question,, do i call the session_start(); command on each page?

#6
kwm

kwm

    Newbie

  • Members
  • PipPip
  • 11 posts
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:

#7
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
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

#8
Nightmare

Nightmare

    Newbie

  • Members
  • Pip
  • 5 posts
Ah right, thanks alot guys :)