Solved

Login Script Help Cant Logout

Posted on 2004-08-19
5
398 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now