I used the following code to configure the facebook API and my structure what to follow is also OK. But I am receiving warning like that.
Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at /customers/2/1/f/mrprofessional.se/httpd.www/ziaullah/index.php:6) in /customers/2/1/f/mrprofessional.se/httpd.www/ziaullah/src/facebook.php on line 49 Login
you can see the error by clicking on that link
The Code is given
<html> <head> <title>PHP SDK</title> </head> <body> <?php require_once 'src/facebook.php'; $facebook = new Facebook(array( 'appId' => '198516340340394', 'secret' => 'f11117b96e0996ecbf7d7f4919c0cf70', 'cookie' => true )); $user = $facebook->getUser(); $user_profile = null; if ($user) { try { $user_profile = $facebook->api('/me'); $facebook->api('/me/feed/', 'post', array( 'message' => 'I want to display this message on my wall' )); } catch (FacebookApiException $e) { error_log($e); $user = null; } } if ($user_profile) { $logoutUrl = $facebook->getLogoutUrl(); echo '<a href="$logoutUrl">Logout</a>'; } else { $loginUrl = $facebook->getLoginUrl(array( 'scope' => 'publish_stream, read_friendlists' )); echo '<a href="$logoutUrl">Login</a>'; } ?> </body> </html>
Please help me if possible I will be thankful
You need to ensure that any code that modifies the HTTP headers is executed before the headers are sent. This includes statements like session_start()
. The headers will be sent automatically when any HTML is output.
Your problem here is that you're sending the HTML ouput at the top of your page before you've executed any PHP at all.
Move the session_start()
to the top of your document :
<?php session_start(); ?> <html> <head> <title>PHP SDK</title> </head> <body> <?php require_once 'src/facebook.php'; // more PHP code here.
Source: Stackoverflow.com