FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


session_destroy problems





imagefree
I am using the following scripts for logging out:

This is logout.php
Code:
<?php
session_start();
//ini_set('error_reporting', DISABLE);
include('php/variables.php');
include('php/functions.php');
connect_database();
if($_GET['redirect'])
{
   $redirect=$_GET['redirect'];
   unset($_GET['redirect']);
}
is_login();
$_GET['redirect']=$redirect;
do_logout();
?>

//what i am doing above with $_GET seems to be strange, but if i dont do this, it will cause problems while running is_login().

here are extracts from function.php (included above).


Code:
function do_logout()
{
   GLOBAL $global_array, $page_list;
   if($global_array['login'])
   {
      if($_SESSION['redirect_'.$_GET['redirect']])
      {
         $redirect_url=$_SESSION['redirect_'.$_GET['redirect']];
         unset($_SESSION);
         setcookie("dname", "", -1);
         setcookie("password", "", -1);
         if(isset($_COOKIE[session_name()]))
            setcookie(session_name(), "", -1, '/');
         session_destroy();
         do_redirect($redirect_url);
      }
      else
      {
         unset($_SESSION);
         setcookie("dname", "", -1);
         setcookie("password", "", -1);
         if(isset($_COOKIE[session_name()]))
            setcookie(session_name(), "", -1, '/');
         session_destroy();
         header("Location: ".WEBSITE.'index.php');
         die;
      }
   }
   else
   {
      if($_SESSION['redirect_'.$_GET['redirect']])
      {
         $redirect_url=$_SESSION['redirect_'.$_GET['redirect']];
         unset($_SESSION);
         do_redirect($redirect_url);
         //echo $redirect_url;
         die;//
      }
      else die(header("Location: ".WEBSITE."login.php"));
   }
}


is_login() checks whether the person is logged in!!

the redirect URL is saved in sessions and everytime user logges out, it saves the referal url in the session and then after logout takes user back to the referal page.

here is the redirecting function

Code:
function do_redirect($redirect_url)
{
   header("Location: ".$redirect_url);
   die;
}


I have been using session_destroy() since the first version of this script and till now i have modified the script 4-5 times but the error below never occured. Now this error is occuring frequantly.

Code:
Warning: session_destroy() [function.session-destroy]: Session object destruction failed in C:\xampp\htdocs\MyWebsite\php\functions.php on line 346

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\MyWebsite\php\functions.php:346) in C:\xampp\htdocs\MyWebsite\php\functions.php on line 352

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\MyWebsite\php\functions.php:346) in C:\xampp\htdocs\MyWebsite\php\functions.php on line 25


Can you tell me what may be the problem? This error is occuring 20% of the times when i try to logout. Rest of the times the code work perfectly.

Please help me making this script perfect.
sonam
I am not sure you can call session_destroy(); before is session empty. Try to unset($_SESSION); and then destroy it.
imagefree
sonam wrote:
I am not sure you can call session_destroy(); before is session empty. Try to unset($_SESSION); and then destroy it.


this is wnat i am doing. See again.

This code was working perfectly before yesterday. Now it gives error sometimes.
kv
call session_destroy() immediately after unset($_SESSION). That should fix session destroy problem. Regarding headers already sent, you cannot call header() after a setcookie (setcookie sends a header, so you cannot send another header after that).
imagefree
kv wrote:
call session_destroy() immediately after unset($_SESSION). That should fix session destroy problem. Regarding headers already sent, you cannot call header() after a setcookie (setcookie sends a header, so you cannot send another header after that).


the code was working previously in the same arrangement.
another problem is that if i change the arrangement and call session_destroy after unset(), then i cant use this code:


Code:
if(isset($_COOKIE[session_name()]))
            setcookie(session_name(), "", -1, '/');
kv
try $_SESSION = array() instead of unset($_SESSION).

If it was working earlier, check what was the change you did after which it stopped working.
Related topics
Facing Many Problems
New forum area (computer problems)
Linux or Windows on your computer?!
Problems With Index Page
FTP problems --> Use Filezilla and/or active mode
problems
Problems with provider
Host Problems
Laptop Bootup Problems...
Gmail Problems
Audio problems
HTML help needed
i heard so many problems just here
if your operating system has problems..
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.