log out

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

Post Reply
yasir_memon
Forum Commoner
Posts: 48
Joined: Tue Aug 11, 2009 12:29 am

log out

Post 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
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: log out

Post 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.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: log out

Post by Ollie Saunders »

+1 what jackpf said. Use sessions for that. Then on the logout page you destroy the session with session_destroy().
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: log out

Post 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.
Post Reply