[php] I am receiving warning in Facebook Application using PHP SDK

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

This question is related to php facebook api sdk

The answer is

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. 

Examples related to php

I am receiving warning in Facebook Application using PHP SDK Pass PDO prepared statement to variables Parse error: syntax error, unexpected [ Preg_match backtrack error Removing "http://" from a string How do I hide the PHP explode delimiter from submitted form results? Problems with installation of Google App Engine SDK for php in OS X Laravel 4 with Sentry 2 add user to a group on Registration php & mysql query not echoing in html with tags? How do I show a message in the foreach loop?

Examples related to facebook

I am receiving warning in Facebook Application using PHP SDK React-Native: Application has not been registered error Can't Load URL: The domain of this URL isn't included in the app's domains Facebook OAuth "The domain of this URL isn't included in the app's domain" Facebook login message: "URL Blocked: This redirect failed because the redirect URI is not whitelisted in the app’s Client OAuth Settings." Warning: Each child in an array or iterator should have a unique "key" prop. Check the render method of `ListView` Open Facebook Page in Facebook App (if installed) on Android App not setup: This app is still in development mode IOS - How to segue programmatically using swift Get ALL User Friends Using Facebook Graph API - Android

Examples related to api

I am receiving warning in Facebook Application using PHP SDK Couldn't process file resx due to its being in the Internet or Restricted zone or having the mark of the web on the file Failed to load resource: the server responded with a status of 404 (Not Found) css Call another rest api from my server in Spring-Boot How to send custom headers with requests in Swagger UI? This page didn't load Google Maps correctly. See the JavaScript console for technical details How can I send a Firebase Cloud Messaging notification without use the Firebase Console? Allow Access-Control-Allow-Origin header using HTML5 fetch API How to send an HTTP request with a header parameter? Laravel 5.1 API Enable Cors

Examples related to sdk

I am receiving warning in Facebook Application using PHP SDK Has been compiled by a more recent version of the Java Runtime (class file version 57.0) Difference between OpenJDK and Adoptium/AdoptOpenJDK Error:Failed to open zip file. Gradle's dependency cache may be corrupt Can't accept license agreement Android SDK Platform 24 Automatically accept all SDK licences Android SDK location should not contain whitespace, as this cause problems with NDK tools Android SDK folder taking a lot of disk space. Do we need to keep all of the System Images? "The following SDK components were not installed: sys-img-x86-addon-google_apis-google-22 and addon-google_apis-google-22" Can't find SDK folder inside Android studio path, and SDK manager not opening