I use Following php code in my wordpress site
<?php
session_start();
require 'src/facebook.php';
include 'config.php';
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret
));
// Get User ID
$user = $facebook->getUser();
if ($user) {
try {
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
}
if ($user) {
echo "loggedin";
}
else
{
echo "not loggedin";
}
?>
But even when i authenticate my app, I keep on getting not loggedin status.
The above code works fine on normal app, But not in my wordpress site, I get session error, header already sent.
Please anyone tell alternative way to solve this problem.
Note: I dont want javascript
That error is actually probably sent when you do session_start, because there was already some non-header elements built and thus the header of the page is already sent. Meaning, you need to do this before any text is shown in previous scripts (e.g. if you’re including this in the middle of somewhere, just do this in a script which is called before).
Since you said this is wordpress and you’re just putting this somewhere, you might want to separate the first part into another part of the project (before the headers are sent) and then use the echoes in this place.
It could also be (I noted you’re using closing ?>), if you’re writing just PHP you might want to avoid using ?> at the end of the files because any blank lines after that might be sent to the output.