Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    May 2008
    Posts
    70
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Header error on 1 server and not another

    Hi, I have a frustrating issue where when I redirect users on a mobile device to my mobile friendly website I get the following:

    Warning: Cannot modify header information - headers already sent by (output started at C:\Server\xampp\htdocs\p3\mb\index.php:2) in C:\Server\xampp\htdocs\p3\mb\index.php on line 3

    This line this error is referring to:

    PHP Code:
    <?php setcookie("mobile","m"time()+3600"/",".begraphics.com"); ?>
    Which allows the user to go back to the desktop site when the link is pressed.

    I uploaded this to another server I control and had no issues...

    i.e.
    http://m.begraphics.com/ = error
    http://www.directionfirst.com/be/mb/ = works fine

    Any idea why it may be working on one and not the other... do I need to contact the server hosts to request something?

    Cheers

    Eddie

  • #2
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    That warning probably means that somewhere before the header is loaded, you have some kind of output to the page, be it a space, dot, any output at all even the smallest item.

    The header must come first, you cannot have any output to the page, not even a space before the header loads or it will give you that warning.

    So look for that issue and this issue should resolve itself.. i would think.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The problem is you have output starting on line 2. Remove the output, and the problem will resolve. The reason why one server works and not the other is because one server has output buffering enabled at an ini level, and the other does not.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by Eddie_E View Post
    This line this error is referring to:

    PHP Code:
    <?php setcookie("mobile","m"time()+3600"/",".begraphics.com"); ?>
    So check the line above it if there is one. You may have something there like whitespace .

    See that? - Between my full stop and the word whitespace I left a space. We call THAT white space. You can't see anything there yet it is valid output which if before your call to setcookie() (or any other header() function) will trigger your headers to be sent.

    I have a link in my signature about this which may help you.
    I can't really think of anything to write here now...

  • #5
    New Coder
    Join Date
    May 2008
    Posts
    70
    Thanks
    4
    Thanked 0 Times in 0 Posts
    oh my god... as simple as a whitespace with all the time spent trying to fix it and trying it on different servers...

    Thanks

    Eddie

  • #6
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,486
    Thanks
    279
    Thanked 32 Times in 31 Posts
    welcome to the wonderful joyus world of php lol.. glad you got it fixed...

    As i like to say,
    "they say character counts in life and that may be true, but in php everything counts!"

    in no time you will be having dreams of code and nothing else lol...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •