Jump to content


Photo

Destroying a session


  • Please log in to reply
5 replies to this topic

#1 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 25 April 2006 - 09:09 PM

Why doesnt this code work? I have never used destory session before so nt sure how to implement it. I simply want to use it as a logout function and then return to the homepage of my website so what am i doing wrong and how should i change it??

<?php

session_destroy();
header("homepage.htm");

?>

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 25 April 2006 - 09:14 PM

use sesssion_unset(); prior to destroy.
follow me on twitter @PHPsycho

#3 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 25 April 2006 - 09:18 PM

How is it not working? Is it it not destroying session variables that have been defined? Are you getting errors?

Asuming the session variable you are trying to get rid of is $sessvariable...try this:
<?php

  session_start();

  session_unregister('sessvariable');

  unset($sessvariable);

  session_destroy();

  header("Location: homepage.htm"); 

?>

Hope that helps.
PHP Ninja

#4 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 25 April 2006 - 09:34 PM

I just want to get rid of any variables. It doesnt seem to be working because a blank white page is output.

#5 sanfly

sanfly
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationNew Zealand

Posted 25 April 2006 - 09:39 PM

I think this

header("homepage.htm");

Should be this:

header("location: homepage.htm");

If you're not part of the solution, you're part of the precipitate

#6 OriginalSunny

OriginalSunny
  • Members
  • PipPipPip
  • Advanced Member
  • 95 posts

Posted 25 April 2006 - 09:42 PM

These errors are ouput in nusphere debugger:

Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in C:\Project\htdocs\logout.php on line 4

Warning: Cannot modify header information - headers already sent by (output started at C:\Project\htdocs\logout.php:4) in C:\Project\htdocs\logout.php on line 5

The thing is its an admin area of the website which i want administrators to be able to log out of. There are some session variables used in the admin area to pass information and post is used to pass values through a lot of the pages. So should i just have a logout which is a link back to the homepage and do i really need to use session_destroy()???

Thanks!! It worked. What a silly error lol.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users