Solved

Login Script Help Cant Logout

Posted on 2004-08-19
5
402 Views
Last Modified: 2008-01-09
hello this is what I have collected untill now, I have learned a little bit of database and cookies,
but I keep getting an error in the "logout.php" when I Login I mark "Remember me next time"
and from the main.php is where I  logout

here is the warning I warning or error
Warning: Cannot modify header information - headers already sent by (output started at /home/www/html/notes1/login.php:147) in /home/www/html/notes1/logout.php on line 7 and 8

I have upload the script to my friend's site here it is the code http://www.astrotarotonline.com/user/xtry/help_logout.rar

I have tried too many things to get it right but im getting crazy now, and decided to look for the professional help.
0
Comment
Question by:Xtry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 

Expert Comment

by:iwarner
ID: 11849279
Maybe something in the include files is creating an output to the screen, this means that you cannot set cookies / edit sessions when this happens.

try this - it seems the includes are unecessary anyway as there are no reference to these in the code.

<?php
      session_start();

// DELETE OLD COOKIES

      if (isset($_COOKIE['KraCookieName']) && isset($_COOKIE['KraCookiePass']))
            {
            setcookie ("KraCookieName", "", time() - 60*60*24*30, "/");
            setcookie ("KraCookiePass", "", time() - 60*60*24*30, "/");
            }

      unset($_SESSION['username']);
      unset($_SESSION['password']);

// kill session variables

      $_SESSION = array(); // reset session array
      session_destroy();   // destroy session.

      if ($logged_in == 0)
            {
            die('You are not logged in so you cannot log out.');
            }

      echo "<h1>Logged Out</h1>\n";
      echo "You have successfully <b>logged out</b>. Back to <a href=\"main.php\">main</a>";
?>
0
 
LVL 6

Accepted Solution

by:
merwetta1 earned 500 total points
ID: 11849305
The error is caused by a couple of extra line feeds at the end of your login.php script. When you include login.php from main.php, the line feeds are being output to the browser and shutting off any further header info (like cookies and sessions). It's an easy mistake.

To fix...open login.php with your text editor and delete everything after the last closing php tag "?>", save, repost, and you will not get the modify header warning. If you need help beyond that, please post.
0
 
LVL 4

Expert Comment

by:sint4x
ID: 11850560
Yeah, you cannot edit the headers after you display the contents of the page
0
 

Expert Comment

by:Dennis_Nielsen
ID: 11850640
I agree, but I don't fully understand why you want the login-script included in the logout script...?

I't should be safe to remove the include files in logout.php.

<?php

if ($logged_in == 0) {
      die('You are not logged in so you cannot log out.');
}

unset($_SESSION['username']);
unset($_SESSION['password']);
// kill session variables
$_SESSION = array(); // reset session array
session_destroy();   // destroy session.

   echo "<h1>Logged Out</h1>\n";
   echo "You have successfully <b>logged out</b>. Back to <a href=\"main.php\">main</a>";

?>
0
 

Author Comment

by:Xtry
ID: 11851552
thanks a lot for the help!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question