Login system with no expire ...

A

Anonymous

Guest
Hi all

Ive seen a lot of login system like this one :
http://www.acecoolco.com/media_tutorialshow.php?id=50
on internet.

they all work fine , but the problem is whenever I close the
browser (IE,NS or whatever) , the session will be expired and
I have to login again !

how can change this code to stay in Login mode unless user wants
to logout himself ?
 
To store login state in client, you can use cookie :
setcookie(name, value, expire, path, domain);
E.g:
Code:
<?php 
setcookie("username", $name, time()+36000);
//sets a cookie named "username" - that expires after ten hours.
?>
When a cookie is set, PHP uses the cookie name as a variable, so to find out if a cookie has been set :
Code:
<?php
if (isset($_COOKIE["username"])) echo "Welcome " . $_COOKIE["username"] . "!<br />";
else echo "You are not logged in!<br />";
?>
 
Thanx a lot mate it works fine
how about if I want to expire the cookie myself ?
Like pressing a LOGOUT button ?
 
just use setcookie(--COOKIENAME--);
that will delete the cookie.. or you can also set the expire time to -1 ... that will also result in deleteing the cookie... look for more information on how to use cookies at http://www.php.net and search for setcookie in a function list
 
Back
Top