A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearphp header function produces an error when it shouldnt - page 1
User InfoPosts
php header function produces an error when it shouldnt#1
Im working with PHP 4.3.11 and when I execute a header always responds with an error like this

Warning: Cannot modify header information - headers already sent by (output started at d:\folder\file.php:1) in d:\folder\file.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at d:\folder\file.php:1) in d:\folder\file.php on line 3
Current PHP version: 4.3.11

the code I used to generate this error was

<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

echo (Current PHP version: ( . phpversion();

// prints e.g. (2.0( or nothing if the extension isn(t enabled
echo phpversion((tidy();
?>


It has no spaces nor newlines before or after the php tags, and the same code in a 5.x version returns just the php version as expected.

Any clue?

Thanks in advance

Edit:
Solved!: I(ve opened the file with western european encoding and deleted the BOM and it worked. Thanks all for your help!

posted date: 2009-04-08 04:48:00


Re: php header function produces an error when it shouldnt#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-08 04:48:01


Re: php header function produces an error when it shouldnt#3
Make sure that there are no empty lines and invisible characters (such as the UTF BOM) before the PHP block so that <?php is really the first in the file.

posted date: 2009-04-08 04:50:00


Re: php header function produces an error when it shouldnt#4
Do you have a UTF BOM at the start of the file?

posted date: 2009-04-08 04:51:00


Re: php header function produces an error when it shouldnt#5
Have you tried a hex editor to check the latter?

posted date: 2009-04-08 04:52:00


Re: php header function produces an error when it shouldnt#6
The error you(re getting means that your entire script (other files included) are sending some output before the header() function is called.You should revise all your files and see if any of them is outputting something (with echo() or print()), or if you missed some empty spaces after the last closing tag ?>

posted date: 2009-04-08 04:53:00


Re: php header function produces an error when it shouldnt#7
if your file does not contain anything else but php code it is recommended to skip the php closing tag to avoid empty spaces issue at the end of the file

posted date: 2009-04-08 04:54:00


Re: php header function produces an error when it shouldnt#8
done with same results, thanks!

posted date: 2009-04-08 04:56:00


Re: php header function produces an error when it shouldnt#9
Thanks! I've checked with another editor and dropped those chars and it worked !!!

posted date: 2009-04-08 05:02:00


Re: php header function produces an error when it shouldnt#10
it(s unlikely, but there(s the possibility to define auto_prepend_file in the php.ini (probably .htaccess too). http://at2.php.net/manual/en/ini.core.php - this acts like a require() at the beginning of every script. you can check this by looking at the phpinfo(); output.but i too think the problem is the utf-8 BOM.

posted date: 2009-04-08 05:03:00


Re: php header function produces an error when it shouldnt#11
Like @solomongaby says, you should skip the closing tag entirely. It is allowed in PHP, and doing so lets you avoid problems with trailing whitespace/linefeed

posted date: 2009-04-08 05:08:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.