Results 1 to 8 of 8

Thread: Header already sent.

  1. #1
    oracle is offline x10 Lieutenant
    Join Date
    Nov 2007
    Posts
    430

    Header already sent.

    Some one kindly help me plz:

    I am consistently getting the following error, Can anyone please help me find where the problem is:

    Warning: Cannot modify header information - headers already sent by (output started at .......php:4) in ..................php on line 68

    I went through a few forums where they stated that the above error occurs due to extra line or space in the file. Well I have checked as far as possible for any additional space or line, but still I am getting the above error.

    Kindly help me through.

  2. #2
    Slothie's Avatar
    Slothie is offline Lord Of The Keys
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: Header already sent.

    Code please

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  3. #3
    oracle is offline x10 Lieutenant
    Join Date
    Nov 2007
    Posts
    430

    Re: Header already sent.

    Well the code is working well when I am testing them on my local machine's IIS Server. I have Windows XP OS. But when I put them on my webspace, they start showing error. Here are the lines of code which it point to.

    Login.php
    -------------
    else {
    // if login is ok then we add a cookie
    $_POST['username'] = stripslashes($_POST['username']);
    $hour = time() + 3600;
    setcookie(ID_my_site, $_POST['username'], $hour);
    setcookie(Key_my_site, $_POST['pass'], $hour);

    //then redirect them to the members area
    header("Location: members.php");
    }

    It points to the two setcookie commands and the redirect command.

    Members.php
    -----------------
    }
    else {
    //if the cookie does not exist, they are taken to the login screen
    header("Location: login.php");
    }
    ?>

    Here it points to the redirect command.

    index.php
    ------------
    <?php
    include_once("googleanalyticscode.php");
    header("Location: login.php");
    ?>

    Here again.

    Kindly help me through.

  4. #4
    Slothie's Avatar
    Slothie is offline Lord Of The Keys
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: Header already sent.

    PHP Code:
    include_once("googleanalyticscode.php"); 
    This outputs something already.


    Anyway you could try this. Prepend
    PHP Code:
    ob_start(); 
    and append
    PHP Code:
    ob_flush(); 
    to all your php files that get this error.


    Your local php.ini probably has output buffering on by default.

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  5. #5
    oracle is offline x10 Lieutenant
    Join Date
    Nov 2007
    Posts
    430

    Re: Header already sent.

    Thanx for the quick Response, however as I put those two commands something else stops working. I will copy and paste my original login.php file, if possible just point me whr do u want me to put those commands:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <?php
    // set your infomation.
    $dbhost='****';
    $dbusername='****';
    $dbuserpass='****';
    $dbname='****';
    // Connects to your Database
    mysql_connect($dbhost,$dbusername,$dbuserpass) or die(mysql_error());
    mysql_select_db($dbname) or die(mysql_error());
    //Checks if there is a login cookie
    if(isset($_COOKIE['ID_my_site'])) {
    //if there is, it logs you in and directes you to the members page
    $username = $_COOKIE['ID_my_site'];
    $pass = $_COOKIE['Key_my_site'];
    $check = mysql_query("SELECT * FROM USERS WHERE username = '$username'") or die(mysql_error());
    while($info = mysql_fetch_array( $check )) {
    if ($pass != $info['password']) {}
    else {
    header("Location: members.php");
    }
    }
    }
    //if the login form is submitted
    if (isset($_POST['submit'])) {
    // if form has been submitted, makes sure they filled it in
    if(!$_POST['username'] | !$_POST['pass']) {
    die('You did not fill in a required field.');
    }
    // checks it against the database
    if (!get_magic_quotes_gpc()) {
    $_POST['email'] = addslashes($_POST['email']);
    }
    $check = mysql_query("SELECT * FROM USERS WHERE username = '".$_POST['username']."'") or die(mysql_error());

    //Gives error if user dosen't exist
    $check2 = mysql_num_rows($check);
    if ($check2 == 0) {
    die('That user does not exist in our database.<a href=index.php>Click Here to Register</a>');
    }
    session_start();
    if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {
    // Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
    unset($_SESSION['security_code']);
    } else {
    // Insert your code for showing an error message here
    die("Wrong Code");
    }
    while($info = mysql_fetch_array( $check )) {
    $_POST['pass'] = stripslashes($_POST['pass']);
    $info['password'] = stripslashes($info['password']);
    $_POST['pass'] = md5($_POST['pass']);
    //gives error if the password is wrong
    if ($_POST['pass'] != $info['password']) {
    die('Incorrect password, please try again.');
    }
    else {
    // if login is ok then we add a cookie
    $_POST['username'] = stripslashes($_POST['username']);
    $hour = time() + 3600;
    setcookie(ID_my_site, $_POST['username'], $hour);
    setcookie(Key_my_site, $_POST['pass'], $hour);
    //then redirect them to the members area
    header("Location: members.php");
    }
    }
    }
    else {
    // if they are not logged in
    ?>

    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
    <table border="0">
    <tr><td colspan=2><h1>Login</h1></td></tr>
    <tr><td>Username:</td><td>
    <input type="text" name="username" maxlength="60">
    </td></tr>
    <tr><td>Password:</td><td>
    <input type="password" name="pass" maxlength="10">
    </td></tr>
    <tr><td>Enter Code:</td><td>
    <input type="text" name="security_code" id="security_code" maxlength="10">
    </td></tr>
    <tr><td colspan="2" align="left">
    <img src="CaptchaSecurityImages.php?width=100&height=30 &characters=5" alt="captcha">
    </td></tr>
    <tr><td colspan="2" align="right">
    <input type="submit" name="submit" value="Login">
    </td></tr>
    <tr><td colspan="2" align="left">
    <a href=registration.php> New User Sign in Here </a>
    </td></tr>
    </table>
    </form>
    <?php
    }
    ?>



    More specifically Captcha image is not being generated after enetering the ob_start() and ob_flush command.

    Kindly have a look at the code and lemme know....
    Thanx in advance

  6. #6
    Slothie's Avatar
    Slothie is offline Lord Of The Keys
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: Header already sent.

    PHP Code:
    <?php
    ob_start
    ();
    // set your infomation.
    $dbhost='****';
    $dbusername='****';
    $dbuserpass='****';
    $dbname='****';
    // Connects to your Database
    mysql_connect($dbhost,$dbusername,$dbuserpass) or die(mysql_error());
    mysql_select_db($dbname) or die(mysql_error());
    //Checks if there is a login cookie
    if(isset($_COOKIE['ID_my_site'])) {
    //if there is, it logs you in and directes you to the members page
    $username $_COOKIE['ID_my_site'];
    $pass $_COOKIE['Key_my_site'];
    $check mysql_query("SELECT * FROM USERS WHERE username = '$username'") or die(mysql_error());
    while(
    $info mysql_fetch_array$check )) {
    if (
    $pass != $info['password']) {}
    else {
    header("Location: members.php");
    }
    }
    }
    //if the login form is submitted
    if (isset($_POST['submit'])) {
    // if form has been submitted, makes sure they filled it in
    if(!$_POST['username'] | !$_POST['pass']) {
    die(
    'You did not fill in a required field.');
    }
    // checks it against the database
    if (!get_magic_quotes_gpc()) {
    $_POST['email'] = addslashes($_POST['email']);
    }
    $check mysql_query("SELECT * FROM USERS WHERE username = '".$_POST['username']."'") or die(mysql_error());

    //Gives error if user dosen't exist
    $check2 mysql_num_rows($check);
    if (
    $check2 == 0) {
    die(
    'That user does not exist in our database.<a href=index.php>Click Here to Register</a>');
    }
    session_start();
    if((
    $_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {
    // Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
    unset($_SESSION['security_code']);
    } else {
    // Insert your code for showing an error message here
    die("Wrong Code");
    }
    while(
    $info mysql_fetch_array$check )) {
    $_POST['pass'] = stripslashes($_POST['pass']);
    $info['password'] = stripslashes($info['password']);
    $_POST['pass'] = md5($_POST['pass']);
    //gives error if the password is wrong
    if ($_POST['pass'] != $info['password']) {
    die(
    'Incorrect password, please try again.');
    }
    else {
    // if login is ok then we add a cookie
    $_POST['username'] = stripslashes($_POST['username']);
    $hour time() + 3600;
    setcookie(ID_my_site$_POST['username'], $hour);
    setcookie(Key_my_site$_POST['pass'], $hour);
    //then redirect them to the members area
    header("Location: members.php");
    }
    }
    }
    else {
    // if they are not logged in
    ?>
    <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
    <table border="0">
    <tr><td colspan=2><h1>Login</h1></td></tr>
    <tr><td>Username:</td><td>
    <input type="text" name="username" maxlength="60">
    </td></tr>
    <tr><td>Password:</td><td>
    <input type="password" name="pass" maxlength="10">
    </td></tr>
    <tr><td>Enter Code:</td><td>
    <input type="text" name="security_code" id="security_code" maxlength="10">
    </td></tr>
    <tr><td colspan="2" align="left">
    <img src="CaptchaSecurityImages.php?width=100&height=30 &characters=5" alt="captcha">
    </td></tr>
    <tr><td colspan="2" align="right">
    <input type="submit" name="submit" value="Login">
    </td></tr>
    <tr><td colspan="2" align="left">
    <a href=registration.php> New User Sign in Here </a>
    </td></tr>
    </table>
    </form>
    <?php
    }
    ob_flush();
    ?>
    Edit:
    By the way,

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    is already considered output to browser
    Last edited by Slothie; 11-20-2007 at 01:36 AM. Reason: Automerged Doublepost

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  7. #7
    oracle is offline x10 Lieutenant
    Join Date
    Nov 2007
    Posts
    430

    Re: Header already sent.

    Lovely, thanx a lot man. It did really worked.

    Thanx a lot.

    I will try out the same thing to the other files too.
    Edit:
    But some thing is happening strange here.

    I changed the things in index.php to look like...

    <?php
    ob_start();
    include_once("googleanalyticscode.php");
    header("Location: login.php");
    ob_flush();
    ?>

    It comes to login.php but the captcha image is not being generated, however when i initially opened the the url /login.php straight, it worked.

    Any comments.?

    Edit:
    Well it worked the first time I made the changes....now again it is continuing with the same problem.
    Last edited by oracle; 11-20-2007 at 02:04 AM. Reason: Automerged Doublepost

  8. #8
    Brandon's Avatar
    Brandon is offline Former Senior Account Rep
    Join Date
    Jun 2006
    Location
    Tewksbury, MA
    Posts
    9,612

    Re: Header already sent.

    Hello,

    It seems your problem has been solved, if you have any more questions then feel free to ask them.
    Thanks,
    Brandon Long | brandon[@]brandonlong[.]me

Similar Threads

  1. Como colocar ads en header de php nuke??
    By pes5champion in forum Free Hosting
    Replies: 8
    Last Post: 10-10-2006, 11:00 PM
  2. Help with ad codes in header vbulletin 3.5
    By parshatim in forum Free Hosting
    Replies: 2
    Last Post: 12-20-2005, 06:36 PM
  3. A new php-nuke header?
    By XColl in forum Scripts, 3rd Party Apps, and Programming
    Replies: 5
    Last Post: 04-21-2005, 09:17 PM

Posting Permissions

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