OriginalSunny Posted April 25, 2006 Share Posted April 25, 2006 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"); ?> Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 25, 2006 Share Posted April 25, 2006 use sesssion_unset(); prior to destroy. Quote Link to comment Share on other sites More sharing options...
Caesar Posted April 25, 2006 Share Posted April 25, 2006 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. Quote Link to comment Share on other sites More sharing options...
OriginalSunny Posted April 25, 2006 Author Share Posted April 25, 2006 I just want to get rid of any variables. It doesnt seem to be working because a blank white page is output. Quote Link to comment Share on other sites More sharing options...
sanfly Posted April 25, 2006 Share Posted April 25, 2006 I think this[code] header("homepage.htm"); [/code]Should be this:[code] header("location: homepage.htm"); [/code] Quote Link to comment Share on other sites More sharing options...
OriginalSunny Posted April 25, 2006 Author Share Posted April 25, 2006 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 4Warning: 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 5The 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.