PHP Rembering Login

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

PHP Rembering Login

Post by reecec »

hi how can i make a login that rembers the username.

i have currently got it as a cookie but gamers can delete the cookie and the timer is ended.


is sesions the same as cookies

please help thanks reece
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

There is nothing you can do, if one deletes the cookie he would have to log in again.
No, a session is not like a cookie. Once the browser is closed - the session doesn't exist any longer.
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

hi

Post by reecec »

how would i be able to do it then so when i ad a timer they cand do anything till the time is up how would i do this with out people being able to stop the timer


thanks reece
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

have it when they login it saves the time. and when they do somthing have it check the time and if it is over the allowed time, log them out and redirect them to a different page.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Log when the timer started in a database and check against that timestamp?

Mac
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

hi

Post by reecec »

thanks

but what would i store the time in
Li0rE
Forum Commoner
Posts: 41
Joined: Wed Jun 07, 2006 6:26 am

Post by Li0rE »

its called a database. you can use a text file or mysql
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

You can't, you can have the control of your server and for the output being sent to the user's browser, but you can never have control on the user's computer.
You can set the lifetime of the session, but when the user closes the browser then the session expires - no matter what.
You may want to check: http://us2.php.net/manual/en/function.s ... params.php
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

hi

Post by reecec »

yes i know a database would not work as it has to be on the users pc

how come i have tried some games and i delete the cookies close the browser and im still loged in

thanks reece
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Re: hi

Post by PrObLeM »

reecec wrote: how come i have tried some games and i delete the cookies close the browser and im still loged in
A couple of reasons ( assuming the game was browser based ):

- You didn't close all the browser windows
- You didn't delete the right cookie
- The browser just auto filled the login form and you clicked login without knowing.
- Some sort of evil dark magic.
janson0
Forum Newbie
Posts: 6
Joined: Thu Jun 01, 2006 11:10 am

Re: hi

Post by janson0 »

PrObLeM wrote: - You didn't close all the browser windows
- You didn't delete the right cookie
- The browser just auto filled the login form and you clicked login without knowing.
- Some sort of evil dark magic.
I vote for option 4...
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

Oren wrote:There is nothing you can do, if one deletes the cookie he would have to log in again.
No, a session is not like a cookie. Once the browser is closed - the session doesn't exist any longer.
This is not exactly true.

If you delete the cookie, but are using sessions, you can pass the session ID via the request to maintain the session.

Likewise, if there is a session cookie set, you can close the browser and reopen it and the session is maintained.
(#10850)
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

I was talking about cookies, not session cookies.
And as far as I know, once you close the browser all sessions expire.
reecec
Forum Contributor
Posts: 218
Joined: Sun Apr 02, 2006 7:12 am

hi

Post by reecec »

sorry yes you right as soon as you close all browsers it logs out

thanks all
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Well... arborint is also right - it all depends on the case. Personally, I use only session cookies. I use an .htaccess file with this code in it:

Code: Select all

php_value session.use_cookies 1
php_value session.use_only_cookies 1
php_value session.use_trans_sid 0
Now, the default PHP value for the cookie lifetime is '0' = 'until the browser is closed'. So, in general, the session expires when the browser is closed as I said before, but if for some reason the cookie lifetime is set to something else, then the session wouldn't expire once the broswer is closed - in this case arborint is right :wink:
Post Reply