71 users online (0 members and 71 guests)  


  Results 1 to 6 of 6

Related

  1. mypsace modify friends help?    Forum: Myspace Forum
    Replies: 0
  2. Premature end of script headers error    Forum: CGI Perl Forum
    Replies: 1
  3. Question about Headers (I think)    Forum: HTML Forum
    Replies: 5
  1. #1
    zzz's Avatar
    New User

    Status
    Offline
    Join Date
    Jan 2009
    Posts
    5

    Warning: Cannot modify header information - headers already sent by (output started a

    hi,
    can anybody help me i this regards.
    problem is as follows

    i have a form .
    here i am getting a value through a file.
    based on the value i decide the header.but before that i pass a meta data also.

    <html>
    <meta http-equiv="refresh" content="2;url=http://localhost/cba.php" />
    <?php
    $handle=fopen('c:/aaa.txt','r');
    $a=fgets($handle);
    fclose($handle);
    if($a!=0)
    header( 'refresh: 5; url=http://localhost/abc.php' );
    else
    header( 'refresh: 5; url=http://localhost/cba.php' );
    ?>
    </html>

    so here once i do this a warning will come up saying
    "Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\abc.php:7) in C:\Program Files\Apache Group\Apache2\htdocs\abc.php on line 462
    "

    so can anyone give me solution for this.pls

  2. #2
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: Warning: Cannot modify header information - headers already sent by (output start

    Sorry about the delayed response. I have been gone for a little while, but I am back now.

    When using the header() function in PHP, there can be nothing output to the screen before the function is called. Any HTML is considered output to the screen. What you need to do is move your PHP code to before the HTML as follows:

    PHP Code:
    <?php
    $handle
    =fopen('c:/aaa.txt','r');
    $a=fgets($handle);
    fclose($handle);
    if(
    $a!=0)
    header'refresh: 5; url=http://localhost/abc.php' );
    else
    header'refresh: 5; url=http://localhost/cba.php' );
    ?>
    <html>
    <meta http-equiv="refresh" content="2;url=http://localhost/cba.php" />
    </html>
    Viola! No more error.
    Last edited by jthayne; 05-29-2009 at 12:53 PM.

  3. #3
    markei's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2009
    Location
    Westminster, MD
    Posts
    19

    Wink Re: Warning: Cannot modify header information - headers already sent by (output start

    Viola? Why not Bass Fiddle?

  4. #4
    kaly's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2009
    Posts
    1

    Re: Warning: Cannot modify header information - headers already sent by (output start

    hi,
    i m getting the same "Cannot modify header information - headers already sent in .. " error. There's no white space b4 or after php tags. Here is my code-

    <? ob_start(); ?>
    <?php
    session_start();
    if(isset($_POST['login']))
    {
    if(!$fh = fopen('pwd.dat','w')) {
    do_error_exit('Error opening data file. <br />Please contact the system administrator. <br />Sorry for the inconvenience.');
    }

    $username1[0]= 'kaly';
    $username1[1]= crypt('mypassword','rl');

    $user_pass_string= implode('=',$username1);
    fwrite($fh,"$user_pass_string\n");

    flock($fh);
    flush($fh);
    fclose($fh);

    $username = $_POST['username'];
    $password = $_POST['pswd'];

    $tempwd = crypt($password,'rl');

    $fh = fopen('pwd.dat','r');

    for($line = fgets($fh); !feof($fh) ; $line = fgets($fh))
    {
    $line = trim($line);
    $userData = explode("=",$line);
    if ($userData[0] == $username)
    $pass = $userData[1];

    }
    fclose($fh);
    if (crypt($password, $pass) == $pass){
    $_SESSION['phplogin'] = true;
    header('Location: index.php');
    exit;
    } else {
    ?>
    <script type="text/javascript">
    <!--
    alert('Wrong Password, Please Try Again')
    //-->
    </script>
    <?php
    }
    }
    ?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title> PHP Login </title>
    </head>
    <body>
    <center>
    Username:<br>
    Password:<br>
    <form method="post" action="">
    <input type="username" name="username">
    <input type="password" name="pswd">
    <input type="submit" name="login" value="Login">
    </form>
    </center>
    </body>
    </html>
    <? ob_flush(); ?>

  5. #5
    sac0o01's Avatar
    New User

    Status
    Offline
    Join Date
    Nov 2009
    Location
    USA
    Posts
    1

    Re: Warning: Cannot modify header information - headers already sent by (output start

    I would say Short Tags are not enabled on your host. You can change it in your php.ini file but it is easiest to fix the code.

    Change:
    PHP Code:
    <? ob_start(); ?>
    To:
    PHP Code:
    <?php ob_start(); ?>
    Remember to change the line at the bottom as well.

  6. #6
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: Warning: Cannot modify header information - headers already sent by (output start

    Actually what needs to happen, is you need to move
    PHP Code:
    <? ob_start(); ?>
    to just before you actually have output you are buffering as this function opens the output buffer which is where your problem lies.

    My recommendation is to move it just before this line:
    HTML Code:
    <script type="text/javascript">



Tags for this Thread