bronzemonkey Posted September 21, 2007 Share Posted September 21, 2007 I've got a LAMP testing server which is putting out the following error for php pages with <?php header('Content-type: text/html; charset=utf-8'); ?> as the second line of code. Warning: Cannot modify header information - headers already sent by (output started at /home/administrator/testwebsite.com/htdocs/index.php:3) in /home/administrator/testwebsite.com/htdocs/head.php on line 2 This isn't occurring on an identical copy of the source code hosted by a commerical web server. What differences are there between my apache setup in my virtual machine and in the commerical server? What is causing the warning to appear? =================== I also have a php contact page which sends its contents to a specified email address (someemail@hotmail.com). How can I test it on my testing server (which can only be accessed from within my small network)? I completed an identical copy of this page, hosted on my testing server, and the email was never sent to "someemail@hotmail.com"...which is good. But where did the contents of the contact page try to send themselves? How can I tell if the php code is working correctly without being able to view the destination of the content? Can someone shed some light on how I can test this code within my virtual server? =================== And finally, how do I set up logs for each specific domain on my apache server? Quote Link to comment https://forums.phpfreaks.com/topic/70077-cannot-modify-header-information-testing-server-problems/ Share on other sites More sharing options...
trq Posted September 21, 2007 Share Posted September 21, 2007 Three questions in one.... Your first issue is that of you php programming. You cannot call the header() function after ANY output has already been sent to the client. There is a massive sticky on the subject in PHP Help. You could hide the error by changing php's error reporting level within your php.ini. I would fix your code instead though. Nothing to do with Apache. I'm not exactly sure what your second question actually is. I think your asking how to send an email from your local server. You need to either setup a local mail (smtp) server, or use a remote smtp server. Once again, these setting are within your php.ini. Nothing to do with Apache. Thirdly, you simply need to add a ErrorLog directive to the root of your vhosts section. One of my vhosts looks like... <VirtualHost *> ServerName foo DocumentRoot /var/www/foo <Directory /var/www/foo> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/foo> Options FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all DirectoryIndex index.php </Directory> ErrorLog /var/log/apache/foo-error.log LogLevel warn CustomLog /var/log/apache/foo-access.log combined ServerSignature On </VirtualHost> Quote Link to comment https://forums.phpfreaks.com/topic/70077-cannot-modify-header-information-testing-server-problems/#findComment-351955 Share on other sites More sharing options...
bronzemonkey Posted September 21, 2007 Author Share Posted September 21, 2007 Thanks for the reply. I just don't get why the header is causing a problem. I read the sticky and can't see how it applies to my code...what is the output that has already been sent to the browser? This is the very first thing that appears in the code. <?php header('Content-type: text/html; charset=utf-8'); ?> As for my second question; I want to be able to test code that sends information to an email address. So if I need my live site to send contact-form information to the email bob@hotmail.com, how can I test (within my testing environment) the code that will achieve this? Thanks for helping me out with the question about the log files. Quote Link to comment https://forums.phpfreaks.com/topic/70077-cannot-modify-header-information-testing-server-problems/#findComment-351985 Share on other sites More sharing options...
bronzemonkey Posted September 21, 2007 Author Share Posted September 21, 2007 I also have the following appearing when the server boots up. I have two virtual hosts which were set up using webmin. *Starting web server (apache2)... apache2: Could not reliably determine the server's fully qualified domain name, using 10.0.0.20 for ServerName [error] Virtual Host *:80 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results [error] Virtual Host *:80 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results Those vhost errors also tie in with my difficulties to get the logs to work. Everything I google talks about the httpd.conf file (which is found at /etc/apache2/httpd.conf on my server) but that file is completely empty on my server. Instead the vhost information has been placed in files at /etc/apache2/sites-enabled and sites-available, which each vhost creating a new file with its info inside. How do I go about giving the server a fully qualified domain name and avoiding the errors associated with my virtual hosts? Quote Link to comment https://forums.phpfreaks.com/topic/70077-cannot-modify-header-information-testing-server-problems/#findComment-352284 Share on other sites More sharing options...
trq Posted September 22, 2007 Share Posted September 22, 2007 1. The error is caused by output being sent to the browser. Make sure there is no[/i] html or whitespace prior to the call to header(). 2. See my last reply. 3. Post your vhost configs. Quote Link to comment https://forums.phpfreaks.com/topic/70077-cannot-modify-header-information-testing-server-problems/#findComment-352843 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.