Jump to content

Destroying a session


OriginalSunny

Recommended Posts

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");

?>
Link to comment
https://forums.phpfreaks.com/topic/8404-destroying-a-session/
Share on other sites

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:
[code]<?php

  session_start();

  session_unregister('sessvariable');

  unset($sessvariable);

  session_destroy();

  header("Location: homepage.htm");

?>[/code]

Hope that helps.
Link to comment
https://forums.phpfreaks.com/topic/8404-destroying-a-session/#findComment-30735
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/8404-destroying-a-session/#findComment-30743
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.