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 04-14-2012, 08:52 AM   PM User | #1
Philly100000
New Coder

 
Join Date: Jun 2010
Location: Regina, Saskatchewan, Canada
Posts: 28
Thanks: 3
Thanked 0 Times in 0 Posts
Philly100000 has a little shameless behaviour in the past
session isnt getting destroyed

PHP Code:
$errorMsg "";
session_start();
setcookie("id"''time()-3600*24*730"/");
setcookie("idx"''time()-3600*24*730"/");
setcookie("username"''time()-3600*24*730"/");
setcookie("useremail"''time()-3600*24*730"/");
setcookie("userpass"''time()-3600*24*730"/");
setcookie("accounttype"''time()-3600*24*730"/");
session_destroy();
sleep(3); 
if(!isset(
$_SESSION['id'])){
    
header("location: index.php");
    exit();
} else {
    
$errorMsg "Logout Error";

When I try to logout it doesn't let me, it removes the cookies, the but session_destroy doesnt seem to get destroyed and I'm still logged in. The Logout Error message is displaying.
Philly100000 is offline   Reply With Quote
Old 04-14-2012, 01:30 PM   PM User | #2
fredrikrob
New Coder

 
Join Date: Sep 2011
Location: NY
Posts: 33
Thanks: 4
Thanked 0 Times in 0 Posts
fredrikrob is an unknown quantity at this point
Hi,

I am not an expert in php but i am learning php for last 4 months and have practiced many times on session's and cookies. As i have gone through your code i have seen that you are not creating session variable but instead your are creating cookies which cannot be deleted by session_destroy() method. As of this code you don't have any session variable so the condition is not getting satisfied and you are getting Logout error message.

Instead of setcookies() you must use $_SESSION["id"]=$anyvariable; to get it worked. Hope it will help you. And no doubt i might be wrong but i am sure that i am not.
__________________
Do you like to change PSD to HTML or PSD to drupal conversion here is the Answer.
fredrikrob is offline   Reply With Quote
Old 04-14-2012, 06:29 PM   PM User | #3
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,505
Thanks: 45
Thanked 439 Times in 428 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
Try using unset():

PHP Code:
unset($_SESSION);
session_destroy(); 
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Users who have thanked tangoforce for this post:
Philly100000 (04-14-2012)
Old 04-14-2012, 08:32 PM   PM User | #4
Philly100000
New Coder

 
Join Date: Jun 2010
Location: Regina, Saskatchewan, Canada
Posts: 28
Thanks: 3
Thanked 0 Times in 0 Posts
Philly100000 has a little shameless behaviour in the past
Quote:
Originally Posted by tangoforce View Post
Try using unset():

PHP Code:
unset($_SESSION);
session_destroy(); 
The unset before the session_destroy fixed the problem, many thanks!
Philly100000 is offline   Reply With Quote
Reply

Bookmarks

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 05:48 AM.


Advertisement
Log in to turn off these ads.