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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.