Current location: Hot Scripts Forums » Programming Languages » PHP » log out function not working


log out function not working

Reply
  #1 (permalink)  
Old 05-13-06, 08:08 AM
cspgsl cspgsl is offline
New Member
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
log out function not working

Any help here appreciated

I insert the menu file via SSI statement. Works fine

I add a logout behavior to the menu and I get warning

Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /home/pencils/public_html/interview/client/firm_info.php:8) in /home/pencils/public_html/interview/includes/left_menu.php on line 3

I remove session_start() at the top of the menu file and add it to the top of all pages that employ the includes statement and the above warning disappears.

However, when I click on the logout link I get another warning

Warning: Cannot modify header information - headers already sent by (output started at /home/pencils/public_html/interview/client/firm_info.php:8) in /home/pencils/public_html/interview/includes/left_menu.php on line 15

Line 15 = header("Location: $logoutGoTo");

And it does not open the logout page.

menu page (that is included)
PHP Code:

<?php

//initialize the session
//session_start();
// ** Logout the current user. **
$logoutAction $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset(
$_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
  
$logoutAction .="&"htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset(
$_GET['doLogout'])) &&($_GET['doLogout']=="true")){
  
//to fully log out a visitor we need to clear the session varialbles
  
session_unregister('MM_Username');
  
session_unregister('MM_UserGroup');
  
$logoutGoTo "../interview/logout.php";
  if (
$logoutGoTo) {
    
header("Location: $logoutGoTo");
    exit;
  }
}
?>
... menu links ... etc
page that menu file is included on
PHP Code:

<?php 

    session_start
()
?>

<?php require('../../Connections/connBSD.php'); ?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {color: #0000FF}
-->
</style>

<link href="/css/template_style.css" rel="stylesheet" type="text/css">

</head>

<body>
<!-- begin div wrapper = entire page -->
<div id="wrapper">
        <div id="header">
          </div>
        <div id="navbar">
        </div>
            <!-- begin div content = right and left columns -->
            <div id="content">
                    <!-- begin div right = right column -->
              <div id="right">
                <h1>webSite Design Interview</h1>

                      <h2> <img src="/images/websites.jpg" width="80" height="95" hspace="10" align="left">Contacts</h2>

                    </div>

                    <!-- begin div left = left column -->
                    <div id="left">
                        <?php require('../includes/left_menu.php'); ?>
            <!-- end div content = right and left columns -->
                    </div>

            </div>
</div>
</body>
</html>
Reply With Quote
  #2 (permalink)  
Old 05-13-06, 08:17 AM
ben.periton ben.periton is offline
Wannabe Coder
 
Join Date: Oct 2004
Posts: 183
Thanks: 0
Thanked 0 Times in 0 Posts
Because you cannot modify any headers once any output has been sent to the browser. If you are trying to include a file that changes the headers, header("Location") etc, after you have already sent HTML to the browser, then it will not work. Try making a seperate logout page that redirects back to ../interview/logout.php
__________________
Ben Periton
http://ben.periton.co.uk
Reply With Quote
  #3 (permalink)  
Old 05-13-06, 08:23 AM
cspgsl cspgsl is offline
New Member
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
You mean link to a page without the includes statement that logs out the user?
Reply With Quote
  #4 (permalink)  
Old 05-13-06, 08:34 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Yeh, make a separate page like this:

PHP Code:

<?php


session_start
();

session_unregister('MM_Username');
session_unregister('MM_UserGroup'); 

session_destroy();

header("Location: ../interview/logout.php");

?>
Reply With Quote
  #5 (permalink)  
Old 05-13-06, 08:43 AM
cspgsl cspgsl is offline
New Member
 
Join Date: May 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
I see why it wouldn't work now... the solution is so simple it escaped me.
Thanks very much.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP upload prob minority ASP 1 06-27-05 08:35 AM
PHP Error Fairnie PHP 8 06-26-04 07:15 AM
Disable form fields to be submitted RickyRod JavaScript 2 05-24-04 10:15 AM
calendar working until months changed bitesize JavaScript 1 01-13-04 01:50 PM
Help trim code down TheLaughingBandit JavaScript 0 09-02-03 09:50 AM


All times are GMT -5. The time now is 07:12 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.