ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a strange problem. We have two servers and I run a php script on them. The script contains only one <?php header("Location....");?> line.
I know there are some hidden character at the beginnig of the scriptfile. The strange thing is the script runs without error on one server, but it generates a "header already sent.." error on another server.
Hidden characters? Do you mean a byte order mark (Wikipedia)? Just remove it. PHP does not recognize it anyway (which IMHO is a good thing, as it makes emitting non-HTML content from PHP simpler). The character set used does not matter to PHP, so just emit a Content-Type header specifying the character set: header('Content-Type: text/html; charset=UTF-8');
If you mean the script begins with a hashbang (AKA shebang, Wikipedia), then the PHP script is intended to be run as a CGI script and not via mod_php. On the problematic server, you need to set that script to be run via mod_cgi, mod_cgid, or mod_fastcgi, and not mod_php. (It should not be difficult to compare the two configurations to see the differences.)
Probably other server has automatic output buffering enabled. You can turn it on your server but this will be stopgap - why you just do not remove these hidden characters from script? Use good editor with option to disable BOM and save it or save in another encoding like Latin1.
Probably other server has automatic output buffering enabled. You can turn it on your server but this will be stopgap - why you just do not remove these hidden characters from script? Use good editor with option to disable BOM and save it or save in another encoding like Latin1.
Thanks for your answer.
Ok, I know if I remove hidden characters from the file, it will run perfectly. But I would like to know what different settings cause this problem.
Hidden characters? Do you mean a byte order mark (Wikipedia)? Just remove it. PHP does not recognize it anyway (which IMHO is a good thing, as it makes emitting non-HTML content from PHP simpler). The character set used does not matter to PHP, so just emit a Content-Type header specifying the character set: header('Content-Type: text/html; charset=UTF-8');
If you mean the script begins with a hashbang (AKA shebang, Wikipedia), then the PHP script is intended to be run as a CGI script and not via mod_php. On the problematic server, you need to set that script to be run via mod_cgi, mod_cgid, or mod_fastcgi, and not mod_php. (It should not be difficult to compare the two configurations to see the differences.)
Thanks for your answer.
The display of cat -v filename is:
M-oM-;M-?<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header("Location: .....");
?>
The /usr/sbin/apachectl -t -D DUMP_MODULES -M command shows same output for both server:
But some php module aren't installed on problematic server, which are installed on another server. These are:
apc, wddx, uploadprogress,soap.
I have installed apc php module and problem is resolved Thanks for all. I guess apc uses output buffering (?) nevertheless output_buffering php.ini variable is 0.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.