Error when requesting Facebook PHP Api?
I normally use only the facebook javascript api, but the login started to give me trouble so I'm trying with the PHP api. This is the api call in my header:
<?
require 'stuff/facebook-php/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'my app id',
'secret' => 'secret',
));
// Get User ID
$user = $facebook->getUser()开发者_开发问答;
?>
I get these messages on my site:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/02/6945202/html/copoetry/index.php:6) in /home/content/02/6945202/html/copoetry/stuff/facebook-php/src/facebook.php on line 37
Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/02/6945202/html/copoetry/index.php:6) in /home/content/02/6945202/html/copoetry/stuff/facebook-php/src/facebook.php on line 37
Am I doing something wrong or what could be the issue? Thanks
"Cannot send session cookie - headers already sent error"
means you've outputted some data on the page and then tried to set headers. Headers must be sent before any html output.
ALSO
"Cannot send session cookie - headers already sent" comes often when the file is encoded in UTF-8 WITH BOM under Windows. When transfered on an UNIX server the BOM is considered as text and sent before any header you can define.
Make sure to remove any spaces, newlines, or other garbage
before an opening <?php
tag or after a closing ?>
Make sure you didn't output any string (including errors) before starting your session.
Do not use ?>
if you are sure your last line of your file is php code
<?php
require 'stuff/facebook-php/src/facebook.php';
$facebook = new Facebook(array(
'appId' => 'my app id',
'secret' => 'secret',
));
// Get User ID
$user = $facebook->getUser();
精彩评论