Advanced Search

Results 1 to 7 of 7

Thread: php header warning help please

  1. #1
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default php header warning help please

    Warning: Cannot modify header information - headers already sent by (output started at D:\XAMPP\xampp\htdocs\freshandfunky\logout.php:3) in D:\XAMPP\xampp\htdocs\freshandfunky\logout.php on line 8

    this is my file:

    Code:
    <?php session_start(); ?>
    
    <?php
    echo "You are now logged out, " . $_SESSION['user'] . ". <br /> We'll see you next time!";
    
    $_SESSION['loggedIn'] = "false";
    
    header("Location: index.php");
    
    ?>
    thanks for any help

  2. #2
    Join Date
    Jan 2008
    Posts
    4,158
    Thanks
    28
    Thanked 623 Times in 619 Posts
    Blog Entries
    1

    Default

    Take a look at ob_start:
    http://us2.php.net/ob_start
    Also make sure that your code in the head part of the document.
    Jeremy | jfein.net

  3. #3
    Join Date
    Jun 2008
    Posts
    589
    Thanks
    13
    Thanked 54 Times in 54 Posts
    Blog Entries
    1

    Default

    Nile, is it possible to display time in the title of the HTML page with PHP?

    -magicyte

  4. #4
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default

    Cool thanks nile i read up a little on that link you posted then did a little research on headers and i got it working exactly how i want it now. thanks for the help!

  5. #5
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,626
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    Quote Originally Posted by magicyte View Post
    Nile, is it possible to display time in the title of the HTML page with PHP?

    -magicyte
    PHP Code:
    <?php
      $time 
    date("h:i:s A");
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
        <head>
            <title><?php print "Current Time is {$time}"?></title>
            <style type="text/css">

            </style>
            <script type="text/javascript">

            </script>
        </head>
        <body>
            <div>Setting the Page Title using PHP</div>
        </body>
    </html>

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    http://dynamicdrive.com/forums/showp...postcount=1337 — 4.1, 4.2. Solving 4.1 will fix your problem. Output buffering is overkill in this particular instance.

    You are not allowed to change the headers after sending output, due to the way HTTP data is structured.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Nov 2007
    Location
    USA
    Posts
    170
    Thanks
    8
    Thanked 22 Times in 22 Posts

    Default

    ok i changed my code to this and works fine now:

    Code:
    <?php 
    session_start();
    header("location: index.php");
    
    $_SESSION['loggedIn'] = "false";
    
    ?>
    do you think i should just session_destroy() instead of setting the login to false? would it be safer?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •