Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-15-2013, 04:57 AM   PM User | #1
Eddie_E
New Coder

 
Join Date: May 2008
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Eddie_E is an unknown quantity at this point
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
Eddie_E is offline   Reply With Quote
Old 02-15-2013, 07:05 AM   PM User | #2
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
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.
durangod is offline   Reply With Quote
Old 02-15-2013, 01:16 PM   PM User | #3
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 02-15-2013, 03:57 PM   PM User | #4
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,493
Thanks: 44
Thanked 438 Times in 427 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please wrap your code in [php] tags. It is a sticky topic and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Old 02-18-2013, 12:28 AM   PM User | #5
Eddie_E
New Coder

 
Join Date: May 2008
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Eddie_E is an unknown quantity at this point
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
Eddie_E is offline   Reply With Quote
Old 02-18-2013, 02:37 AM   PM User | #6
durangod
Senior Coder

 
Join Date: Nov 2010
Posts: 1,177
Thanks: 214
Thanked 31 Times in 30 Posts
durangod is on a distinguished road
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...
durangod is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 07:16 PM.


Advertisement
Log in to turn off these ads.