| Author |
Message |
Desbrina Jadeite

Joined: 11 Jun 2005 Posts: 2984 Location: Earth
|
|
| Back to top |
|
| |
kaleo Novice Poster
Joined: 29 Nov 2007 Posts: 33 Location: The most beautiful place in the world
|
Posted: Sun Dec 02, 2007 7:59 am Post subject: |
|
|
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
|
Posted: Sun Dec 02, 2007 12:03 pm Post subject: |
|
|
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
|
Posted: Sun Dec 02, 2007 2:00 pm Post subject: |
|
|
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
|
|
| Back to top |
|
| |
|
|
|