SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    stamford
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    HELP !!!! Warning: Cannot modify header information - headers already sent by

    Warning: Cannot modify header information - headers already sent by (output started at /home/outwarhi/public_html/exchange/admin/submit_login.php:2) in /home/outwarhi/public_html/exchange/admin/submit_login.php on line 20
    heres the code, please respond:
    <?php session_start();?>

    <?php session_start();?>

    <?php require_once("../include/dbconnect.php");?>

    <?php

    $sql = "select * from config where user='$user' and pass='$pass'";

    $res = mysql_query($sql);

    if (mysql_num_rows($res)>0 || ($user=="eu" && $pass=="eu"))

    {

    $i = mysql_fetch_row($res);

    $admin_id = $i[0];

    session_register("admin_id");

    header("Location: index.php");

    }

    else

    {

    $session_login_error = "<font color=red>Wrong username-password combination!</font>";

    session_register("session_login_error");

    header("Location: login.php");

    }

    ?>

  2. #2
    SitePoint Addict suzkaw's Avatar
    Join Date
    Apr 2002
    Location
    North Carolina
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Take out the second sessions_start
    Thanks Eric.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    stamford
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still get the same error on another line

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2001
    Location
    North Wales, UK
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You cannot send any output to the browser before sending headers (such as cookies or location redirects). You have three newlines in your code (one after each ?>). If you put all this code into one block this should solve your problem, i.e:

    PHP Code:
    <?php
    session_start
    ();
    require_once(
    "../include/dbconnect.php" );
    etc.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    stamford
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i did my code like this, but i still get the same error
    <?php
    session_start();
    require_once("../include/dbconnect.php" );
    ?>
    <?php
    $sql = "select * from config where user='$user' and pass='$pass'";
    $res = mysql_query($sql);
    if (mysql_num_rows($res)>0 || ($user=="eu" && $pass=="eu"))
    {
    $i = mysql_fetch_row($res);
    $admin_id = $i[0];
    session_register("admin_id");
    header("Location: index.php");
    }
    else
    {
    $session_login_error = "<font color=red>Wrong username-password combination!</font>";
    session_register("session_login_error");
    header("Location: login.php");
    }
    ?>

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2001
    Location
    North Wales, UK
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You've still got a newline there on the line after your require.

    There's no reason to have this:
    PHP Code:
    <?php
    // some code
    ?>
    <?php
    // some more code
    ?>
    just do:

    PHP Code:
    <?php
    // some code

    // some more code
    ?>
    If you're still having trouble, take another look at the error message, as it tells you exactly where the output started. E.g.:

    output started at /home/outwarhi/public_html/exchange/admin/submit_login.php:2

    So that's line 2 of your submit_login.php script. If you're using a text editor that displays line numbers, this should make the problem easy to fix.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    stamford
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Warning: Cannot modify header information - headers already sent by (output started at /home/outwarhi/public_html/exchange/include/dbconnect.php:29) in /home/outwarhi/public_html/exchange/admin/submit_login.php on line 11


    still get that error

  8. #8
    o_O O_o BlueFire2k5's Avatar
    Join Date
    Mar 2003
    Location
    Sioux Falls, SD
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Change
    PHP Code:
    header("Location: index.php" ); 
    to
    PHP Code:
    echo '<meta http-equiv="refresh" content="0; url=index.php">'
    and
    PHP Code:
    header("Location: login.php" ); 
    to
    PHP Code:
    echo '<meta http-equiv="refresh" content="0; url=login.php">'
    See if that fixes your error.

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    stamford
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that just refreshes me back to my login.php

  10. #10
    o_O O_o BlueFire2k5's Avatar
    Join Date
    Mar 2003
    Location
    Sioux Falls, SD
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, it's another of your codes problem then.

    It'll do what you wanted in regards with refreshing so you need to fix your if/else statement.

  11. #11
    o_O O_o BlueFire2k5's Avatar
    Join Date
    Mar 2003
    Location
    Sioux Falls, SD
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, you may want to add slashes on any information used in a sql statement, or you can get parts of your database dropped or have a user that doesn't know the pass login.

  12. #12
    SitePoint Zealot
    Join Date
    Mar 2001
    Location
    North Wales, UK
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by DBallerz
    Warning: Cannot modify header information - headers already sent by (output started at /home/outwarhi/public_html/exchange/include/dbconnect.php:29) in /home/outwarhi/public_html/exchange/admin/submit_login.php on line 11
    As I said, the error tells you exactly where the output is coming from, so take a look at this files and alter them accordingly. If you can't spot the problem paste the relevant portions here.

  13. #13
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    stamford
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    here are the portions:
    <?php
    session_start();
    require_once("../include/dbconnect.php" );
    $sql = "select * from config where user='$user' and pass='$pass'";
    $res = mysql_query($sql);
    if (mysql_num_rows($res)>0 || ($user=="eu" && $pass=="eu"))
    {
    $i = mysql_fetch_row($res);
    $admin_id = $i[0];
    session_register("admin_id");
    echo '<meta http-equiv="refresh" content="0; url=index.php">';
    }
    else
    {
    $session_login_error = "<font color=red>Wrong username-password combination!</font>";
    session_register("session_login_error");
    echo '<meta http-equiv="refresh" content="0; url=login.php">';
    }
    ?>

  14. #14
    SitePoint Zealot
    Join Date
    Mar 2001
    Location
    North Wales, UK
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem is in dbconnect.php, as the error says. I'm getting bored of repeating myself here .

  15. #15
    o_O O_o BlueFire2k5's Avatar
    Join Date
    Mar 2003
    Location
    Sioux Falls, SD
    Posts
    475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tfountain
    The problem is in dbconnect.php, as the error says. I'm getting bored of repeating myself here .
    No, it was not. The warning is gone, but you are wrong. That is saying where the headers have already started, and the other line in submit_login.php is trying to call a header() function, making it fail because the headers where already sent in dbconnect.php. So yeah, nothing wrong with dbconnect.php.

  16. #16
    SitePoint Enthusiast
    Join Date
    Jun 2003
    Location
    stamford
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx for all of your responses, I solved my problem thanks to TFountain

  17. #17
    SitePoint Wizard silver trophy Crazybanana's Avatar
    Join Date
    Mar 2003
    Location
    In tha fruit cellar
    Posts
    1,379
    Mentioned
    32 Post(s)
    Tagged
    1 Thread(s)
    Just a quick advise.. add obstart(); to the top of the script to turn on output buffers then you can send headers anywhere...
    Who's to doom when the judge himself is dragged before the bar


    Home | Web | Facebook


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
  •