I have got this code to login with the user if there is not anyone.
index.php, located in http://DOMAIN.COM/PATH.
Here, if the user id returned is 0, the login url is taken from facebook instance and a redirection is made to that url to login with a facebook user. Then, after the authorize action, the next url iss "http://DOMAIN.COM/PATH/check.php" where the "getUser" method is again executed, however, the user id is 0 again.
`
$fbPermissions = 'read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos';
$site_url = "http://DOMAIN.COM/PATH/check.php";
$facebook = new Facebook(array(
'appId' => 'MY_ID',
'secret' => 'MY_SECRET_ID',
'cookie' => true
));
$user = $facebook->getUser();
if($user) {
try{
echo "user id insid if=".$user;
$user = $facebook->api('/me');
} catch (Exception $e){}
} else {
$loginUrl = $facebook->getLoginUrl(array('scope'=>$fbPermissions,'redirect_uri'=>$site_url));
header('location:'.$loginUrl.'');
}
?>
Code of check.php
<?php
include_once("facebook.php");
$fbPermissions = 'read_stream, publish_stream, user_birthday, user_location, user_work_history, user_hometown, user_photos';
$facebook = new Facebook(array(
'appId' => 'MY_ID',
'secret' => 'MY_SECRET_ID',
'cookie' => true
));
$user = $facebook->getUser();
if($user) {
try{
echo "user id insid if=".$user;
$user = $facebook->api('/me');
} catch (Exception $e){}
} else {
echo "No user";
}
?>
Thus, in options in my app of facebook developers page, I have the " Site URL" option with this value "http://DOMAIN.COM/PATH/". I have had to create a Website platform in "configuration" section.
I am working in a internet hosting not in localhost.
Which can be the problem? I am really stuck