Page 1 of 1

PHP Header Errors?

Posted: Thu Jun 03, 2010 6:15 am
by Adam Cochran
So recently I was developing a Facebook Application that embeds a SWF Flash game, after countless discussions on the Facebook dev forums I'm told the facebook code is fine it is just a problem with the PHP somewhere. It was suggested I try the ob_start() function but I'm not familiar it at all, but I tried to apply it based on what I could read up on it but I couldn't get it. Here are my errors, the sections of the code that produce them and the applications I applied. Anyone got any ideas on what the issue may be?

Code: Select all

Warning: Cannot modify header information - headers already sent by (output started at /home/content/88/5410988/html/hhlinks/cb/index.php:8) in /home/content/88/5410988/html/hhlinks/cb/facebook.php on line 397

Warning: Cannot modify header information - headers already sent by (output started at /home/content/88/5410988/html/hhlinks/cb/index.php:8) in /home/content/88/5410988/html/hhlinks/cb/facebook.php on line 397

Warning: Cannot modify header information - headers already sent by (output started at /home/content/88/5410988/html/hhlinks/cb/index.php:8) in /home/content/88/5410988/html/hhlinks/cb/facebook.php on line 397

Warning: Cannot modify header information - headers already sent by (output started at /home/content/88/5410988/html/hhlinks/cb/index.php:8) in /home/content/88/5410988/html/hhlinks/cb/facebook.php on line 401
So I attempt to wrap the PHP on line 8 with the ob_start() like so:

Code: Select all

<?php
ob_start();
require_once 'facebook.php';

$appapikey = 'XXXXXXXXXXXXXXXXXXXXXXXXXXX';
$appsecret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$facebook = new Facebook($appapikey, $appsecret);
$user_id = $facebook->require_login();
ob_end_flush();
?>
So then I tried wrapping the PHP code starting at line 397 on facebook.php in the ob_start() like so:

Code: Select all

 ob_start();
    foreach ($cookies as $name => $val) {
      setcookie($this->api_key . '_' . $name, $val, (int)$expires, '', $this->base_domain);
      $_COOKIE[$this->api_key . '_' . $name] = $val;
    }
    $sig = self::generate_sig($cookies, $this->secret);
    setcookie($this->api_key, $sig, (int)$expires, '', $this->base_domain);
    $_COOKIE[$this->api_key] = $sig;
ob_end_flush();
Neither of these suppressed the header code. I also tried to standardize the game code to make the game appear but no changes took place even once it read like so:

Code: Select all

<fb:swf swfsrc="http://www.hhlinks.net/CB2.swf" swfbgcolor="#000000" wmode = "opaque" width="500" height="500" imgsrc="http://www.hhlinks.net/cb/logo.jpg" width='600' height='570' />
So still a little unsure - don't think I made any progress in these attempts

Re: PHP Header Errors?

Posted: Thu Jun 03, 2010 2:09 pm
by JakeJ
It might help if you actually told us which line was 397.

Re: PHP Header Errors?

Posted: Thu Jun 03, 2010 6:24 pm
by Christopher
The problem is that on the lines specified there is output that is being sent to the browser. It may only be a return or space, but any output will force headers to be sent and cause this problem.

Re: PHP Header Errors?

Posted: Thu Jun 03, 2010 6:44 pm
by JakeJ
Look at the following two lines:

Code: Select all

 <php? session_start() ?>

Code: Select all

<php? session_start() ?>
So you see the space before the <?php opening tag? That could cause your failure.

Also, if you're using this page and in include fed in to another page, you probably have output on the first page which would also cause your failure.

Re: PHP Header Errors?

Posted: Fri Jun 04, 2010 2:43 am
by Coburn64
It can also be caused by errors that PHP spits out in the output (like Warnings, etc).