I am trying to write a facebook login, but it doesn't work, I've stripped down the code to the essential or problematic parts as shown below: I found out that the getUser method always return 0 whether a user is logged in to facebook or not, I've studied similar questions on SO but couldn't find the solution. What could be wrong? Thanks.
<?php
require 'facebook/facebook.php';
$app_id = "123456";
$app_secret = "xyz";
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
$user = $facebook->getUser();
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
error_log($e);
$user = null;
}
// Do stuff here
else {
echo "$user";
}
?>