PHP Header Errors?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Adam Cochran
Forum Newbie
Posts: 1
Joined: Thu Jun 03, 2010 6:09 am

PHP Header Errors?

Post 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
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: PHP Header Errors?

Post by JakeJ »

It might help if you actually told us which line was 397.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: PHP Header Errors?

Post 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.
(#10850)
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: PHP Header Errors?

Post 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.
Coburn64
Forum Newbie
Posts: 5
Joined: Fri Jun 04, 2010 2:17 am

Re: PHP Header Errors?

Post by Coburn64 »

It can also be caused by errors that PHP spits out in the output (like Warnings, etc).
Post Reply