Solved

Login Script Help Cant Logout

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
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 …

746 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

10 Experts available now in Live!

Get 1:1 Help Now