Jump to content

Header problems migrating from development on Windows to Linux server


DLR

Recommended Posts

I have developed a small programme on my laptop (Windows XP) and am running WAMP on it. My programmes run fine on the laptop but simply dont work on the shared server - a linux platform also running Apache.

 

This simple programme outputs this error "Warning: Cannot modify header information - headers already sent by (output started at /usr/www/users/celciu/apps/test.php:1) in /usr/www/users/celciu/apps/test.php on line 2"

 

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

 

I have tried using ob_start(); but get the same error -just now says line 3

 

<?php 
ob_start();
header("Location: CEL100.php");
ob_end_flush();
?>

 

I am thoughrly confused. Any assistance would be appreciated.

Link to comment
Share on other sites

You should have been developing (and always should) in an environment that has error_reporting set high, and display errors switched on. This is likely the difference between the two environments in question as there is generally no difference (besides a few extensions) in php between Windows and Linux.

 

Have you read the  sticky regarding header errors?

Link to comment
Share on other sites

Thanks for the pointers, but

 

1. Have ready sticky,

2. Have searched forum before posting

3. Am developing with error reporting on (Not sure if it is set to "high" will check that

4. No white space  - the code is only 3 lines including php tags!

 

The code works in other files on same web address. So I must be doing something different here.

I'm searching for my error - like "permissions". Any other pointrs would be appreciated.

 

The main question is how can there be output if there is only "<?php" before the header? (and definately no whitespace either)

And the offending line is line 1 - the php tag!

Also why does the ob-start() not make a difference?

 

I conclude that the environment must be different - but I cannot see what setting, or possibly ini setting I need to look at.

Link to comment
Share on other sites

The main question is how can there be output if there is only "<?php" before the header?

 

If there are no actual characters in the file before the <?php tag, then your file has been saved as a UTF-8 encoded file and the BOM (search if you don't know what that means) characters that your editor placed at that start of the file are the output that is preventing the header from working.

 

Save your file either as an ANSI encoded file or if you must save it as a UTF-8 encoded file, save it without the BOM. If your editor does not have the option of saving a file using either of the suggested methods, you need to use a better programming editor.

Link to comment
Share on other sites

Thanks guys. Today has been a learning curve.

I appreciate the time all of you have shared with me.

 

The problem was that somehow I had filed this file in utf-8 - and you were correct it was the BOM(Byte order Mark - yes I did look it up aread quite a lot on it!)

 

In passing I note you (PFMaBiSmAd) reccomend coding in ASCII - but I read that WW3 recommends and encourages utf-8 for HTML5. Would you share your motivation for recommending ASCII?

 

Many thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.