Jump to content

Archived

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

OriginalSunny

Destroying a session

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

?>

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
I think this

[code] header("homepage.htm"); [/code]

Should be this:

[code] header("location: homepage.htm"); [/code]

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.