Lifelesspeople.com

 Forum FAQsForum FAQs  Knowledge BaseKnowledge Base  RulesRules   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   HostingHosting   RegisterRegister 
 DonateDonate   WikiWiki   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

keep me logged in question

 
Lifelesspeople.com Forum Index -> Web Architects' Abode
Post new topic   Reply to topic View previous topic :: View next topic  
Author Message
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2984
Location: Earth

PostPosted: Sun Dec 02, 2007 5:47 am    Post subject: keep me logged in question Reply with quote

I'm looking at a keep me logged in type thing for my website and was wondering what the best way of going about it is.

I currently use sessions to log in, but when the browser is closed their logged out

can anyone tell me what the best solution is?
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Caretaker - A Star Trek Voyager TCG
Back to top
 
kaleo
Novice Poster


Joined: 29 Nov 2007
Posts: 33
Location: The most beautiful place in the world

PostPosted: Sun Dec 02, 2007 7:59 am    Post subject: Reply with quote

For that, you'd probably need to use cookies. "Sessions" refer to the browser session, which naturally ends when the browser is closed. Cookies, on the other hand, remain active for the time that you set them for. To set a cookie that will last for 60 days, you would do something like:

Code:

<?php

$timeLimit = 60 * 60 * 24 * 60 + time();
setcookie('timeoflastvisit', date("G:i - m/d/y"), $timeLimit);

 ?>


so what that does, is set a cookie named timeoflastvisit, then you give it
the value of the current date (you could give it the value of 'username' or
something else, and then give it the time limit of $timeLimit, which you could set for 3 days or 2 months or whatever.

And then to retrieve it:

Code:

<?php
if(isset($_COOKIE['timeoflastvisit'])) {
   $visit = $_COOKIE['timeoflastvisit'];
echo("Your last visit was - ". $visit);
}
else {
   echo "You're cookie has expired!";
}

?>


So what that does is check to see if the cookie is set. If it is, then it puts the value of timeoflastvisit (in this case, we'd set it to the date of the last visit) and puts it in the variable $visit, the prints the statement. If it isn't set, then the user gets a message saying that the cookie has expired.

If you wanted to, you could set a cookie with the value of the user's password or something, and then after the user logs in verify the password -- and if the cookie has expired make them log in.

See how it works?

If I was unclear, then let me know and I'll try and make it clearer.
_________________
There is no good or evil, there is only the flute -- and those too weak to play it
Back to top
 
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2984
Location: Earth

PostPosted: Sun Dec 02, 2007 12:03 pm    Post subject: Reply with quote

i think i understand all except for this bit
Quote:
If you wanted to, you could set a cookie with the value of the user's password or something, and then after the user logs in verify the password -- and if the cookie has expired make them log in.


It might help if i explain what i'm going to be using it for.

On my website i have several games that require you to enter your username and password. I basically want to make it so that there's 1 login page, and you'll only need to log in after you've logged out or after 7 days
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Caretaker - A Star Trek Voyager TCG
Back to top
 
marinaroz
Grey Scaled


Joined: 04 Mar 2004
Posts: 2836
Location: Israel

PostPosted: Sun Dec 02, 2007 2:00 pm    Post subject: Reply with quote

You just set a cookie with username, password and expiry date of that cookie (read up a php tutorial on cookies) and when the user accesses your site, you check whether they have a cookie - cookies are stored in the user's computer of course.

If they got one, the user is automatically logged in, otherwise direct them to login page.
_________________
Tarakana NET
Back to top
 
Desbrina
Jadeite


Joined: 11 Jun 2005
Posts: 2984
Location: Earth

PostPosted: Sun Dec 02, 2007 2:37 pm    Post subject: Reply with quote

thanks, got it working (at the moment anyway on a test page, now to see if i can actually implement it)
_________________
Midnight Tempest - A Sailor Moon TCG
Balanced Force - A Star Wars TCG
Caretaker - A Star Trek Voyager TCG
Back to top
 
Display posts from previous:   
Post new topic   Reply to topic    Lifelesspeople.com Forum Index -> Web Architects' Abode All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Home | Hosting | News | Forum | Links | System Status | About | Archive | Donate ]
Powered by phpBB © 2001, 2002 phpBB Group
All trademarks and copyrights on this page are owned by their respective owners. Posts and comments are owned by the poster. Everything else © 2001 - 2007 Lifelesspeople.com