I have the following code which redirects the user to log into facebook and tries to retrieve the session but the session is NULL:
<?php
session_start();
require 'vendor/autoload.php';
use Facebook\FacebookSession;
use Facebook\FacebookRedirectLoginHelper;
FacebookSession::setDefaultApplication('Foo', 'Bar');
$helper = new FacebookRedirectLoginHelper('Baz');
$loginUrl = $helper->getLoginUrl();
echo '<a href="' . $loginUrl . '">Log In</a>';
$session = $helper->getSessionFromRedirect();
// This displays [NULL] always
echo '[' . gettype($session) . ']';
?>
I don't understand why the $session is always NULL. Please help.
What made the real difference to me was the redirect Url address i was using. Hours and hours because of a slash.
Explaining with examples:
(Wrong)
(Right)
I've read a ton of tutorials and answers on Stackoverflow and this final slash was the real answer. I hope it helps someone
Here is solution to use same page as FB redirection page:
Don't call
getLoginUrl()
when facebook redirect you to same page, just add the proper session check to check valid facebook session (Please refer following code example)