User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 401,646 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,701 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1577 | Replies: 13 | Solved
Reply
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 170
Reputation: lordx78 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Help Re: session log out problem

  #11  
Feb 28th, 2008
  1. <?php
  2. // This is the logout page for the site.
  3.  
  4. // Include the configuration file for error management and such.
  5. require_once ('mysql_connect.php');
  6.  
  7. // Set the page title and include the HTML header.
  8. $page_title = 'Logout';
  9. include ('./includes/header.html');
  10. $MM_redirectLoginFailed = "index.html";
  11. $MM_redirecttoReferrer = true;
  12.  
  13. // If no first_name variable exists, redirect the user.
  14. if (isset($_SESSION['first_name'])) {
  15.  
  16. // Start defining the URL.
  17. //$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
  18. // Check for a trailing slash.
  19. //if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
  20. //$url = substr ($url, 0, -1); // Chop off the slash.
  21. //}
  22. // Add the page.
  23. //$url .= '/index.html';
  24.  
  25. ob_end_clean(); // Delete the buffer.
  26. //header("Location: $url");
  27. //header("Location: index.html");
  28. echo "<script type='text/javascript'>location.href='$MM_redirectLoginSuccess';</script>";
  29. exit(); // Quit the script.
  30.  
  31. } else { // Logout the user.
  32.  
  33. $_SESSION = array(); // Destroy the variables.
  34. session_destroy(); // Destroy the session itself.
  35. //session_unset();
  36. setcookie (session_name(), '', time()-300, '/', '', 0); // Destroy the cookie.
  37.  
  38. }
  39.  
  40. // Print a customized message.
  41. echo "<h3>You are now logged out.</h3>";
  42.  
  43. include ('./includes/footer.html');
  44. ?>

I've tried this code and the errors are:

Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in C:\xampp\htdocs\cycle\logout.php on line 34

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\cycle\includes\header.html:7) in C:\xampp\htdocs\cycle\logout.php on line 36

Please help.
"I might not be the BEST but I'm not like the REST!"
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: session log out problem

  #12  
Feb 29th, 2008
Warning: session_destroy() [function.session-destroy]: Trying to destroy uninitialized session in C:\xampp\htdocs\cycle\logout.php on line 34

That means you are trying to destroy a session that doesn't exist.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Oct 2007
Location: Penang Island, Malaysia
Posts: 170
Reputation: lordx78 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 2
lordx78's Avatar
lordx78 lordx78 is offline Offline
Junior Poster

Re: session log out problem

  #13  
Feb 29th, 2008
I've solved it. Thank you all for your kind help.
"I might not be the BEST but I'm not like the REST!"
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 239
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: session log out problem

  #14  
Feb 29th, 2008
Cool ! congrats !
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 6:26 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC