Facebook API Library destroying session/cookie data - php

I have on my generic sign in page a button that allows a user to log in via facebook. Also, i have the following code just prior to the user clicking the button so i can pass a redirect url to the callback after oauth2 authorization and redirect the logged in user somewhere.
<?php
session_start();
require_once __DIR__ . '/vendor/autoload.php'; // change path as needed
$fb = new \Facebook\Facebook([
'app_id' => 'appid',
'app_secret' => 'appsecret',
'default_graph_version' => 'v2.10',
]);
$helper = $fb->getRedirectLoginHelper();
$url=$helper->getLoginUrl("https://example.com/fblogin/callback");
$_SESSION['redirect']='somehurl';
setcookie("redirect","example.com");
header("Location: $url&scope=email");
Then I have
In my callback I have
<?php
session_start();
var_dump($_SESSION['redirect']); //null
var_dump($_COOKIE['redirect']); // null
I dont understand why but facebook is destroying my cookie and session data. Im using version 2.10

Related

login with facebook open in Android facebook Application in PHP?

I was implement login with Facebook in PHP It's perfect Works But i want if website open in mobile browser then redirect in Mobile Facebook Application if Not then mobile browser. How can Do ?
here some code
require_once __DIR__ . '/Facebook/autoload.php'; // download official fb sdk for php # https://github.com/facebook/php-graph-sdk
$fb = new Facebook\Facebook([
'app_id' => '*****************',
'app_secret' => '*******************',
'default_graph_version' => '***',
]);
$helper = $fb->getRedirectLoginHelper();
$loginUrl = $helper2->getLoginUrl('URL', $permissions);
//here login with facebook button
Log in with Facebook!
This code redirect only facebook in browser.
Help me .
Thnakyou

Login using Facebook-PHP-SDK

Very new to php and I am trying to figure out how to use Facebook-PHP-SDK. I set up an account on Facebook Developers and am trying to get data from my own Facebook, which I have linked to my developer account. I am trying to implement the following practice code but I am confused about the login URL. Am I suppose to put my own Facebook URL for that? Or something else?
Practice Code
session_start();
$fb = new Facebook\Facebook([
'app_id' => '{app-id}', // Replace {app-id} with your app id
'app_secret' => '{app-secret}',
'default_graph_version' => 'v3.3',
]);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['email']; // Optional permissions
$loginUrl = $helper->getLoginUrl('https://example.com/fb-callback.php', $permissions);
echo 'Log in with Facebook!';
You should put in the login url the link of the file content your code:
example, this mean the file who contains the current code:
$loginUrl = "http://localhost/login.php"
and the https://example.com/fb-callback.php must redirect to a (file/url) in your application to verify the authentication and extract the access token for example.

FaceBook signup Show error

i have making Facebook signup in php.when i cliked on Facebook login btn they show me this error "Insecure Login Blocked: You can't get an access token or log in to this app from an insecure page. Try re-loading the page as https://"
this is config.php file code
<?php
session_start();
require_once "Facebook/autoload.php";
$FB = new \Facebook\Facebook([
'app_id' => '571388466554956',
'app_secret' => '8381c3ba6df5f1d44ab8643be299e8dd',
'default_graph_version' => 'v2.10'
]);
$helper = $FB->getRedirectLoginHelper();
?>
OK The first step I think is to download the latest version of the Facebook SDK. Local tests showed this to me.

PHP Facebook logout

I am using PHP SDK for creating facebook login, which works fine but when I want to logout and I use getLogoutUrl method which returns logout url in this form:
https://www.facebook.com/logout?next=google.com&access_token=my_access_token
After I redirect to this page I get to the This page is not avalible page on FB and I am not logged out. Any idea what could be wrong ? or it will be SDK bug ? thanks.
I have created a article for facebook login logout with graph api with php. You can see the following code for logout from facebook with php. This is code for logout.php
session_start();
if(isset($_SESSION['fb_access_token'])){
require_once 'php-graph-sdk-5.5/src/Facebook/autoload.php';
$fb = new Facebook\Facebook([
'app_id' => 'app-id', // Replace {app-id} with your app id
'app_secret' => 'app-id-secret',
'default_graph_version' => 'v2.4',
]);
$url = 'https://www.facebook.com/logout.php?next=your-website-return-url/&access_token='.$_SESSION['fb_access_token'];
session_destroy();
header('Location: '.$url);
}
If you need full source code then you can see this link

Length of param app_id must be less than or equal to 32

I'm writing a Facebook login integration using the PHP SDK and running into the above error.
On our main page we have the following code to request public_profile and email.
$fb = new Facebook\Facebook([
'app_id' => '{our_app_id}',
'app_secret' => '{our_app_secret}',
'default_graph_version' => 'v2.4']);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['public_profile', 'email'];
$loginUrl = $helper->getLoginUrl('http://oursiteurl/includes/fbcallback.php/',
$permissions);
This code pops open a new window, processes the Facebook login, authorizes the app permissions, and sends us back to fbcallback.php. Users can disallow revealing their email to our app, but our app absolutely must have being email. So fbcallback.php evaluates whether or not we received the email. If it did we enter a new record in our database; if not, I want it to present an option to rerequest the email permissions. For this I'm trying the following:
$fb = new Facebook\Facebook([
'app_id' => '{our_app_id}',
'app_secret' => '{our_app_secret}',
'default_graph_version' => 'v2.4']);
$helper = $fb->getRedirectLoginHelper();
$permissions = ['public_profile', 'email'];
$accessToken = $helper->getAccessToken();
$redirect = "http://media.pvplive.com/includes/fbcallback.php/";
$loginUrl = $helper->getLoginUrl($redirect, $permissions, TRUE);
Basically, I'm looping back to fbcallback.php, but this time with the rerequest flag set to TRUE. I receive no complaints on landing on fbcallback.php the first time, but when I click on the link for the new $loginUrl it throws the following error:
Length of param app_id must be less than or equal to 32
I haven't been able to find any answers explaining this error yet or what needs to be corrected to get rid of it. I'm using the answer provided here for code for rerequesting permissions already denied using the PHP SDK.

Categories