Author Topic: Logging out  (Read 480 times)

NewCoder72

  • New Member
  • *
  • Posts: 9
  • Karma: 0
    • View Profile
Logging out
« on: March 24, 2012, 03:42:41 PM »
Difficulty: Super easy

This is just something very quick and basic. Here is a logout code. I added in comments.

PHP Code: [Select]
<?php
session_start
();
//That continues on the started session

session_destroy();
//That destroyed the session

header('Refresh: 3; index.php');
exit();
//That means that you will be redirected to the main page in 3 seconds

echo "Logged out. Redirecting in 3 seconds";
//That should be straightforward

?>


I know this is very basic.

dyr

  • Regular Member
  • **
  • Posts: 42
  • Karma: 2
    • View Profile
    • Virtus
Re: Logging out
« Reply #1 on: March 27, 2012, 05:31:51 PM »
If you are storing any information in your settings (like username, password, ID#) it's could to unset those as well!  Adding on to your code here:

PHP Code: [Select]
session_start();

unset(
$_SESSION['username']);
unset(
$_SESSION['email']);
unset(
$_SESSION['password']);
$_SESSION = array();
session_destroy();

header('Refresh: 3; index.php');
exit();


echo 
"Logged out. Redirecting in 3 seconds";


ErnieAlex

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 1858
  • Karma: 32
    • View Profile
Re: Logging out
« Reply #2 on: March 28, 2012, 01:48:16 AM »
Not sure, but, shouldn't you echo the 3 second notice before you header it out?
Don't think it will be seen without using it before exiting...

daveismyname

  • Senior Member
  • ****
  • Posts: 301
  • Karma: 6
  • PHP Helper
    • View Profile
    • PHP Help Tutorials
Re: Logging out
« Reply #3 on: March 28, 2012, 03:17:59 AM »
Not sure, but, shouldn't you echo the 3 second notice before you header it out?
Don't think it will be seen without using it before exiting...

I think your right as the refresh will show the message but the exit command will stop the script going any further, is it won't get to the echo at all.