Page 1 of 1

log out

Posted: Thu Aug 20, 2009 3:34 am
by yasir_memon
guys

using php i want to logout means user can only enter from login page if he click on any href or link it display enter your user name and password in login page

Re: log out

Posted: Thu Aug 20, 2009 7:58 am
by jackpf
Well, you'll need to check if the user is logged in on each page.

If not, redirect them to the login page.

Re: log out

Posted: Thu Aug 20, 2009 8:16 am
by Ollie Saunders
+1 what jackpf said. Use sessions for that. Then on the logout page you destroy the session with session_destroy().

Re: log out

Posted: Thu Aug 20, 2009 10:55 am
by Sindarin
if you use sessions,

Code: Select all

session_destroy();
if you use cookies:

Code: Select all

setcookie("username", "", time()-3600);
setcookie("password", "", time()-3600);
etc.

(see here for info on how to expire a cookie: http://www.tech-recipes.com/rx/1501/php ... er_cookie/)

you may want to redirect using meta refresh

Code: Select all

 
echo '<meta http-equiv="refresh" content="6;URL=http://www.yoursite.com/index.php" /> You are now being logged out.';
 
(you should also put a link to the destination page for those with no meta redirect support.)

or php header

Code: Select all

header('Location: index.php');
afterwards.