Simple Logout Session link

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
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Simple Logout Session link

Post by fariquzeli »

What's the easiest and best way to create a simple link that ends the session and logs the user out?
honkyinc
Forum Newbie
Posts: 19
Joined: Tue Jun 04, 2002 10:30 am
Location: Maryland, USA

Post by honkyinc »

I always had a logout.php page that logged the user out, then redirected to my index.php page.

Code: Select all

<?php

session_destroy();
header("Location: index.php");

?>
fariquzeli
Forum Contributor
Posts: 144
Joined: Mon Jun 24, 2002 9:16 am
Location: Chicago
Contact:

Post by fariquzeli »

thanks, that's how i had it setup, just wanted to make sure it was adequote. :)
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

Actually:

Code: Select all

<?php

session_start();
session_destroy();
header("Location: index.php");

?>
If the session isn't continued first, PHP won't know what session to destroy, and it won't work. I've tested this myself.
Post Reply