0

PHP - Warning: Cannot modify header information - headers already sent by
php header problem.
header('Location: http://www.php.net/');
cannot redirct webpage.
XAMPP PHP: 5.2.9
you must open php.ini (C:\xampp\php\php.ini)
find
output_buffering = off
change
output_buffering = 4096
restart xampp.
OK.
PHP de header komutu ile sayfa yönlendiremiyorum.
XAMPP PHP: 5.2.9 kullanıcısıyım.
C:\xampp\php\php.ini dosyasında
output_buffering = off
değerini
output_buffering = 4096
değiştirdikten sonra xampp yeniden başlattım.
Sorun çözüldü.

0

Thank you JaniF. I also joined DANIWEB because of you. You have helped me a lot with your expertise.

I Googled on this problem and found your simple solution, JeniF. Because of you, I joined DaniWeb. Thought you should know that even 2 years later your reply is still helping people!

Thanks, JeniF!! And thanks DaniWeb!

John

0

dont use ECHO function before using header. otherwise it will give error as you are saying.

0

I am using wordpress in localhost. i have deceloped a plugin, but it is not working

error msg is :
Warning: Cannot modify header information - headers already sent by (output started at /var/www/wordpress/wp-includes/functions.php:3641) in /var/www/wordpress/wp-includes/functions.php on line 791

Warning: Cannot modify header information - headers already sent by (output started at /var/www/wordpress/wp-includes/functions.php:3641) in /var/www/wordpress/wp-includes/functions.php on line 792


line 791: setcookie( 'wp-settings-' . $user->ID, $settings, time() + 31536000, SITECOOKIEPATH );
line 792: setcookie( 'wp-settings-time-' . $user->ID, time(), time() + 31536000, SITECOOKIEPATH );

0

Just wanted to do the same, thank jeniF for her simple yet grand solution. It's mid 2010, and it's still helping people-- THANK YOU!!!!

Paul

0

i have a problem just like you.

use this

if ($pass != $info['password']) 
{ ?>
<script language="javascript">location.replace("login.php"); </script>
<?
}

and use this too

else
//if the cookie does not exist, they are taken to the login screen
{ 
?>
    <script language="javascript">location.replace("login.php"); </script>
<?
}

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

0

The "headers already sent" error is usually caused by having white space before or after the opening and closing PHP tags (<?php . . . ?>).

Have you recently edited any files?

and alsu use top of page <?php ob_start(); ?> it remove all header error from form

0

thanks to jenif that worked perfectly. I just find this forum thread by googing.. It is very helpful. This solution is still work

Thanks a lot jenif...May Allah give your reward

0

I Googled on this problem and found your simple solution, JeniF. Because of you, I joined DaniWeb. Thought you should know that even 2 years later your reply is still helping people!

Thanks, JeniF!! And thanks DaniWeb!

John

Hi.
I am joining this community just to say thanks to JeniF, after 3 years, that answer is still helping people :)
Thanks all.

0

Just found your site and was having days of problems with a script I bought - a bit of bravery (I so am not technical) and I altered the script like you said and BINGO!!!! thank you so much. This will be my first port of call for any kinds of these problems.

0

If you are getting error like "Warning: Cannot modify header information - headers already sent by (output started at /path/file.php:1)" it means you've got some output before your header() call or starting a session. *No* output can be sent. that includes whitespace (outside of <?php and ?>) and any (X)HTML. You can also use output buffering

0

If you are getting error like "Warning: Cannot modify header information - headers already sent by (output started at /path/file.php:1)" it means you've got some output before your header() call or starting a session. *No* output can be sent. that includes whitespace (outside of <?php and ?>) and any (X)HTML. You can also use output buffering

i aggree, i had the same case. And i found a white space before <?php tags. And it have been succeded then my code is work :)

0

I was facing this problem for 2 moths.. Tried everything... nothing happens....

But finaly this blog helped me...... Thanx But can you please elaborate these two tags..

I mean what what is there working...

<? ob_start(); ?>


<? ob_flush(); ?>

0

Thanks JeniF!

Edited by Ezzaral: Snipped url. Please restrict such links to your site-wide user signature, which can be edited from the user control panel.

0

I cant seem to find the error in my code and all I get is"Cannot modify header information - headers already sent by (output started at...". please help.

<?php

// Connects to your Database

mysql_connect("localhost", "root", "") or die(mysql_error());

mysql_select_db("employer") or die(mysql_error());


//checks cookies to make sure they are logged in
if(isset($_COOKIE))
{
$username = $_COOKIE;

$pass = $_COOKIE;

$check = mysql_query("SELECT * FROM user WHERE username = '$username'")or die(mysql_error());

while($info = mysql_fetch_array( $check ))

{

//if the cookie has the wrong password, they are taken to the login page

if ($pass != $info)

{ header("Location: login.php");

}

//otherwise they are shown the admin area

else

{

echo "Admin Area<p>";

echo "Your Content<p>";

echo "<a href=logout.php>Logout</a>";

}

}

}

else

//if the cookie does not exist, they are taken to the login screen

{

header("Location: login.php");

}

?>

0

I have tried all the suggested solutions but non of them is working. Could it be a problem of how I have saved my files?

0

Hi all. I tried many methods but it don't work.

I use denwer.
Look at my code and who can say please my error about (Warning: Cannot modify header information - headers already sent by (output started at Z:\home\localhost\www\Websiter\ChaT.php:1) in Z:\home\localhost\www\Websiter\ChaT.php on line 3)

This is my code

<?php
header("Location: google.ru");
?>

<html>
<head>
<title>Chat</title>

</head>

<body>

<?
if($_POST["chat_write"] != "") 
{
    $chattext = $_POST["chat_write"];
    $chatfile = fopen("chater.txt", "a+b") or die("Error");
    fwrite($chatfile, "$chattext\r\n");
    fflush($chatfile);
}
?>

<div style="font-weight:900"></div>

</div><div style="text-align:center; border:0.5em groove #666; background-color:#444; height:300px; margin-top:100px; width:500px; margin-left:auto; margin-right:auto;">
<?php
$handle = fopen("chater.txt", "a+b");

while(!feof($handle)) {
	$fileIn=fgets($handle);
    echo "<div style='color:orange; border:1px groove black; margin:1px; font-weight:500'>$fileIn</div>";
}
fclose($handle);
?>
</div>
<form name="chat_field" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<div align="center"><textarea name="chat_write" rows="3" cols="55"></textarea>
<input type="submit" name="sbmt" value="ChaT" /></div>

</form> 

</body>
</html>
0

Thanks Jenif The output buffer tags <? ob_start(); ?> before the php opening tag and <? ob_flush(); ?> after the php closing tag works perfectly. it eliminates the white spaces introduced by most editors. The white spaces before and after the php opening and closing tags are the culprits for this error.

for example:

<? ob_start(); ?>
            <?php
            $_SERVER[PHP_AUTH_USER] = htmlentities($_POST['uname']);
            $_SERVER[PHP_AUTH_PW] = htmlentities($_POST['upass']);
            // Connect to the MySQL database
                mysql_pconnect("localhost","root","")
                or die("Can't connect to database server!");
                mysql_select_db("airline_db")
                or die("Can't select database!");
                // Create and execute the selection query
                $query = "SELECT username, pswd FROM logins
                WHERE username='$_SERVER[PHP_AUTH_USER]' AND
                pswd='$_SERVER[PHP_AUTH_PW]' ";
                $result = mysql_query($query);
                // If nothing was found, reprompt the user for the login information
                if (mysql_num_rows($result) == 0) {
                echo "Invalid User";
                } else {
                    header("location: bookflight.html");
                    exit();
                  }
                 ?>
<? ob_flush(); ?>

Edited by mike_2000_17: Fixed formatting

0

Hi HM0729, enclose your php code blocks inbetween <? ob_start(); ?>
and <? ob_flush(); ?> Should work fine. Cheers

0

Hi all...
I'm reading this solution in 2011...and it's still usefull...
thanks JeniF....it's the solution that I looking for... :)

0

This solution is so helpful for me, i have faced this problem since long time, and now i resolved this issue, thank u very much.

0

I am so much happy to signin in this site. Many technical problem Now I can solve .
Thanks again.............

0

<?php ob_start("ob_gzhandler"); ?> Instant compressed code, as well as space correction
perhaps a better solution

Edited by almostbob: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.