I have a developer environment setup with WAMP, WordPress, and PHPEdit IDE. I use the Facebook, Twitter, and YouTube API’s in a sidebar. I’m using Facebook’s PHP SDK to display information(no login or admin functions). Since the FB SDK and WP use session_start() I get the following warning:
Warning: session_start() [function.session-start]: Cannot send session
cache limiter – headers already sent (output started at
C:wampwwwdfiwp-contentthemesDFIheader.php:12) in
C:wampwwwdfiwp-contentthemesDFIapifacebook.php on line 36
I’m trying to figure this out by using the warning output but it doesn’t help considering the following. I know about clearing white space and characters before and after <?php ?>
and placing session_start() before any http output. I use unix line enders and UTF8 encoding without BOM. My host server is not set up for output_buffering.
header.php line 11 to 13
11 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
12 <html xmlns="http://www.w3.org/1999/xhtml" <?php language_attributes();?>>
13 <head>
It looks like the warning comes from inline php code. I don’t know what I can do to fix this line.
facebook.php line 34 to 37
34 public function __construct($config) {
35 if (!session_id()) {
36 session_start();
37 }
I don’t think I can stop either FB or WP from calling session_start() without breaking everything. How do I make WordPress and Facebook play nicely together without this error?
EDIT:
To stop the warning from displaying I put @ in front of session_start().
public function __construct($config) {
if (!session_id()) {
@session_start();
}
Its only a workaround and I would still like to find the root of the problem.
As discovered in your comments, the issue isn’t about including the PHP file, rather it is where you define the class. Creating the instance of the Facebook class can be safely done (as far as I know, it works for me) in the
wp
hook. This will allow you to define the instance of the class before any HTML output, then you can use that variable anywhere in your class.You do however want to be sure to only include the class once, but you can instantiate the class as many times as you want.
Here’s a basic example to get you started:
You can using Hook Action init to check session_id exist or not.