Reputation: 692
Ok i made a code where i connect the user to my database and then i set as login to that user, if the email is already in the database i just Login the user...
The problem is logout button is not working.. i have tried.
session_start();
session_destroy();
On the Logout, but as soon as is redirected to the index page, (i think is loged in again)
how can i avoid this..
EDIT: i dont want the user to be loged out from facebook. just loged out from my site
This is my code.
<?php
if ($userId) {
//
// already logged? show some data
$userInfo = $facebook->api('/' + $userId);
if (isset($userInfo['email']))
{ include "facebookregister.php"; } else { echo "no hay permisos de facebook"; }
} else {
//
// use javaascript api to open dialogue and perform
// the facebook connect process by inserting the fb:login-button
?>
<div id="fb-root"></div>
<fb:login-button scope='email,user_birthday'></fb:login-button>
<?php
}
?>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : <?=YOUR_APP_ID?>,
status : true,
cookie : true,
xfbml : true,
oauth : true,
});
FB.Event.subscribe('auth.login', function(response) {
// ------------------------------------------------------
// This is the callback if everything is ok
window.location.reload();
});
};
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
</script>
And the logout.
function logout_action()
{
$srv_nms=BASE;
$srv_nms=str_replace("http://","",$srv_nms);
$srv_nms=str_replace("https://","",$srv_nms);
$srv_nms=str_replace("www.","",$srv_nms);
$srv_pats=$srv_nms;
$srv_nms_arr=explode("/",$srv_nms);
$srv_nms=$srv_nms_arr[0];
$srv_pats=str_replace($srv_nms."/","",$srv_pats);
setcookie(COOKIE_LOGINID,"",0,"/".$srv_pats,$srv_nms);
setcookie(COOKIE_USERNAME,"",0,"/".$srv_pats,$srv_nms);
setcookie(COOKIE_PASSWORD,"",0,"/".$srv_pats,$srv_nms);
session_start();
session_destroy();
header("Location: ".$this->make_url("user/login/l"));
die;
}
Upvotes: 0
Views: 176
Reputation: 6140
I think I would use a cookie. Upon logout, set a cookie telling you that the have requested logout. Then on the main page, before grabbing data from facebook API, check for the cookie. Obviously you would have to overwrite or expire the cookie upon login...but this should solve it for you.
Upvotes: 1
Reputation: 413
in logout action you are logging out by session_destroy which will clear session in your server only, not in api.
so you need make $facebook->api logout request to logout from facebook completly. NOTE: refer api documentation for logout request.
Upvotes: 0