Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-22-2011, 07:08 PM   PM User | #1
amcf1992
Regular Coder

 
Join Date: Jul 2011
Posts: 114
Thanks: 7
Thanked 0 Times in 0 Posts
amcf1992 is an unknown quantity at this point
Exclamation logout code not functioning

So I'm trying to build a logout script. When i am in account.php I click logout and then navigate back to the account.php to see if vars have been destroyed, but even after I run the script, it does not seem to be destroying session data. Any help would be awesome.

My session vars:

PHP Code:
$_SESSION['id'] = $row['id']; 
        
$_SESSION['firstname'] = $row['firstname']; 
        
$_SESSION['lastname'] = $row['lastname']; 
        
$_SESSION['address'] = $row['address']; 
My logout code:

PHP Code:
<?php

// Initialize the session.
// If you are using session_name("something"), don't forget it now!
session_start();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
    
$params session_get_cookie_params();
    
setcookie(session_name(), ''time() - 42000,
        
$params["path"], $params["domain"],
        
$params["secure"], $params["httponly"]
    );
}

// Finally, destroy the session.
session_destroy();



echo 
'<META HTTP-EQUIV="Refresh" Content="0; URL=login.php">';   
?>
amcf1992 is offline   Reply With Quote
Old 09-22-2011, 08:05 PM   PM User | #2
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Try this ... I'm sort of guessing ...

PHP Code:
<?php
session_start
();

// Unset all of the session variables.
$_SESSION = array();

// If it's desired to kill the session, also delete the session cookie.
// Note: This will destroy the session, and not just the session data!
if (ini_get("session.use_cookies")) {
    
$params session_get_cookie_params();
    
setcookie(session_name(), ''time() - 42000,
        
$params["path"], $params["domain"],
        
$params["secure"], $params["httponly"]
    );
}

// Finally, destroy the session.
if(session_start()){  
session_destroy();
}

header("location: login.php");

?>

.
mlseim is offline   Reply With Quote
Old 09-22-2011, 08:39 PM   PM User | #3
amcf1992
Regular Coder

 
Join Date: Jul 2011
Posts: 114
Thanks: 7
Thanked 0 Times in 0 Posts
amcf1992 is an unknown quantity at this point
I tried that, yet it is still not destroying the session variables
amcf1992 is offline   Reply With Quote
Old 09-22-2011, 08:44 PM   PM User | #4
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
Try this ... the most basic, just to see if that works.

PHP Code:
<?php
session_start
();

if(
session_start()){  
session_destroy();
}

header("location: login.php");
?>

.
mlseim is offline   Reply With Quote
Old 09-22-2011, 08:47 PM   PM User | #5
amcf1992
Regular Coder

 
Join Date: Jul 2011
Posts: 114
Thanks: 7
Thanked 0 Times in 0 Posts
amcf1992 is an unknown quantity at this point
I just tried that, yet no luck
amcf1992 is offline   Reply With Quote
Old 09-22-2011, 08:54 PM   PM User | #6
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,046
Thanks: 8
Thanked 1,029 Times in 1,020 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
I'm stumped.
mlseim is offline   Reply With Quote
Old 09-23-2011, 01:14 PM   PM User | #7
Wanna
Regular Coder

 
Join Date: Sep 2011
Posts: 128
Thanks: 2
Thanked 21 Times in 21 Posts
Wanna is an unknown quantity at this point
PHP Code:
session_destroy();
$_SESSION = array(); 
If this don't work (I doubt that it works) try to enable error's

PHP Code:
error_reporting(E_ALL);
ini_set('display_errors','On'); 
Wanna is offline   Reply With Quote
Old 09-23-2011, 08:34 PM   PM User | #8
Time Sheep
New Coder

 
Join Date: Sep 2011
Posts: 61
Thanks: 9
Thanked 1 Time in 1 Post
Time Sheep is an unknown quantity at this point
You need to unset the variables...
PHP Code:
session_start();
session_unset();
session_destroy(); 
Time Sheep is offline   Reply With Quote
Reply

Bookmarks

Tags
authentication, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:00 AM.


Advertisement
Log in to turn off these ads.