LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-04-2011, 03:23 AM   #1
hakansukur
LQ Newbie
 
Registered: Jul 2011
Location: Hungary
Posts: 9

Rep: Reputation: Disabled
php header() function and hidden characters


Hello

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.

If you know any solution, please reply!

Thanks
hs
 
Old 08-04-2011, 03:44 AM   #2
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
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.)
 
Old 08-04-2011, 03:48 AM   #3
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
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.
 
Old 08-04-2011, 04:34 AM   #4
hakansukur
LQ Newbie
 
Registered: Jul 2011
Location: Hungary
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by eSelix View Post
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.
 
Old 08-04-2011, 04:49 AM   #5
hakansukur
LQ Newbie
 
Registered: Jul 2011
Location: Hungary
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Nominal Animal View Post
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:

core_module (static)
authn_file_module (static)
authn_default_module (static)
authz_host_module (static)
authz_groupfile_module (static)
authz_user_module (static)
authz_default_module (static)
auth_basic_module (static)
include_module (static)
filter_module (static)
deflate_module (static)
log_config_module (static)
logio_module (static)
env_module (static)
expires_module (static)
headers_module (static)
unique_id_module (static)
setenvif_module (static)
version_module (static)
proxy_module (static)
proxy_connect_module (static)
proxy_ftp_module (static)
proxy_http_module (static)
proxy_scgi_module (static)
proxy_ajp_module (static)
proxy_balancer_module (static)
ssl_module (static)
mpm_prefork_module (static)
http_module (static)
mime_module (static)
dav_module (static)
status_module (static)
autoindex_module (static)
asis_module (static)
suexec_module (static)
cgi_module (static)
dav_fs_module (static)
dav_lock_module (static)
negotiation_module (static)
dir_module (static)
actions_module (static)
userdir_module (static)
alias_module (static)
rewrite_module (static)
so_module (static)
suphp_module (shared)


But some php module aren't installed on problematic server, which are installed on another server. These are:
apc, wddx, uploadprogress,soap.
 
Old 08-04-2011, 07:13 AM   #6
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Quote:
Originally Posted by hakansukur View Post
I would like to know what different settings cause this problem.
How you saved this file, which editor are you using?
 
Old 08-04-2011, 09:05 AM   #7
hakansukur
LQ Newbie
 
Registered: Jul 2011
Location: Hungary
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by eSelix View Post
How you saved this file, which editor are you using?
Vim and I used to :wq command
 
Old 08-04-2011, 09:13 AM   #8
hakansukur
LQ Newbie
 
Registered: Jul 2011
Location: Hungary
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hakansukur View Post
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.

hs
 
Old 08-04-2011, 02:30 PM   #9
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,281

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
In vim you can enter a command
Code:
:set nobomb
to remove these hidden characters when saving file.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ignoring Hidden Characters whocares357 Linux - Newbie 5 11-03-2010 02:41 PM
Bluefish not showing hidden (?) non-ASCII characters? ta0kira Programming 3 04-12-2008 03:52 PM
JavaScript - How to get value from a function for use as hidden input? win32sux Programming 4 01-01-2008 08:32 AM
need help in PHP header() function ArulPrabhuT Programming 1 11-26-2004 10:17 AM
Passing one php function result as a parameter to another php function davee Programming 13 09-12-2004 12:08 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration