zang8027 Posted January 19, 2009 Share Posted January 19, 2009 I have this php book and it doesn't mention anything about stopping a session. Im using a session to have a log in for this site. Now, i am working on a log out page that will stop the session. Is there a function for that? I guess i could set the session to equal nothing ($_SESSION['priv'] = "") if that even works but is there a better way to make it "sign out" the user? Quote Link to comment Share on other sites More sharing options...
trq Posted January 19, 2009 Share Posted January 19, 2009 Take a look at the example script on the session_destroy man page. Quote Link to comment Share on other sites More sharing options...
npsari Posted January 19, 2009 Share Posted January 19, 2009 To stop a session, you simply use session_destroy(); If you are using Cookies to remember your members log-in, you delete the cookies by setting the time of the cookies to negative Quote Link to comment Share on other sites More sharing options...
revraz Posted January 19, 2009 Share Posted January 19, 2009 Just remember to use session_start() before session_destroy(). Quote Link to comment Share on other sites More sharing options...
trq Posted January 19, 2009 Share Posted January 19, 2009 To stop a session, you simply use session_destroy(); If you are using Cookies to remember your members log-in, you delete the cookies by setting the time of the cookies to negative As the manual states, callingsession_destroy alone isn't enough to completely kill a session. Quote Link to comment Share on other sites More sharing options...
zang8027 Posted January 19, 2009 Author Share Posted January 19, 2009 another weird problem. It logs it out BUT i get the following error at the top of the page: Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/tyzangme/public_html/ClickNDine/html/logout.php:1) in /home/tyzangme/public_html/ClickNDine/html/logout.php on line 2 Warning: Cannot modify header information - headers already sent by (output started at /home/tyzangme/public_html/ClickNDine/html/logout.php:1) in /home/tyzangme/public_html/ClickNDine/html/logout.php on line 9 Here is my code <?php session_start(); // Unset all of the session variables. $_SESSION = array(); // If it's desired to kill the session, also delete the session cookie. // Note: This will destroy the session, and not just the session data! if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } session_destroy(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Click N Dine - Online Food Ordering Service</title> <meta name="keywords" content="Business Travel, Food, Dine Online, Click And Dine, Eat Online, Local Restaurants" /> <meta name="description" content="Click N Dine offers the ability to recieve food from local restaurants from around your area! No need to pick up the phone, just order online, and wait for it at your door!" /> <link rel="stylesheet" href="../css/global.css" media="screen" type="text/css" /> </head> <body> <div id="wrapper"> <div id="header"> <img src="../Images/siteLogo.gif" alt="Click N Dine" id="mainTitle"/> <div class="headerText"> <p><b>Welcome </b>- Have an account already? <a href="login.php">Sign In</a></p> <p><a href="#">My Account </a>|<a href="#"> My Receipts</a> | <a href="#">Customer Feedback</a></p> </div><!--headerText --> </div><!-- header --> <div id="navigation"> <ul> <li><a href="../index.php">Home</a></li> <li><a href="findrestaurants.php">Find Restaurants</a></li> <li class="Shopping"><a href"#">Cart</a></li> </ul> </div> <!--navigation --> <div class="clearingDiv"></div> <div id="mainMiddle"> <?php print "Signed out succesfully"; ?> </div> <div id="footer"> <hr /> <p><span class="subNavText">Home | Find Restaurants | Shopping Cart | My Account | My Receipts | Customer Feedback</span></p> <br /> <p><span class="subNavText">Company Policy | Privacy Statement | Contact Us | Terms of Service </span></p> </div> </div><!-- Wrapper --> </body> </html> Quote Link to comment Share on other sites More sharing options...
zang8027 Posted January 19, 2009 Author Share Posted January 19, 2009 do i need a process page that has nothing printed out? Quote Link to comment Share on other sites More sharing options...
revraz Posted January 19, 2009 Share Posted January 19, 2009 Sounds like you have whitespace before your session_start(). Quote Link to comment Share on other sites More sharing options...
zang8027 Posted January 19, 2009 Author Share Posted January 19, 2009 thank ya! that was it 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.