i have a website with this URL https://en.economarks.com/ the website is build with WordPress the main thing is to check if user is logged in to his face book account and if not a button will display to connect to face book .
i have created a php page inside the them by the name formReg
<?php
session_start();
require 'vendor/autoload.php';
$fb = new \Facebook\Facebook([
'app_id' => '65656565655665',
'app_secret' => '????????????????',
'default_graph_version' => 'v2.7'
]);
$helper = $fb->getRedirectLoginHelper();
$login_url = $helper->getLoginUrl("https://en.economarks.com/wp-content/themes/twentyseventeen/FormReg.php");
try {
$accessToken = $helper->getAccessToken();
if(isset($accessToken)){
$_SESSION['token'] = (string)$accessToken;
header("Location:https://en.economarks.com/form");
}
} catch (Exception $exc){
$exc->getTraceAsString();
}
echo $_SESSION['token'];
if(isset($_SESSION['token'])){
try
{
$fb->setDefaultAccessToken($_SESSION['token']);
$res = $fb->get('/me?fields=name,email,location,gender,birthday,hometown', $_SESSION['token']);
$user = $res->getGraphUser();
echo $user->getField('name');
$id = $user->getField('id');
echo $user->getField('email');
$picter = "https://graph.facebook.com/".$id."/picture?type=large&width=720&height=720";
echo $useremail = $user->getField('email');
} catch (Exception $exc){
$exc->getTraceAsString();
}
}
?>
<?php if(isset($_SESSION['token'])) : ?>
<?php else : ?>
<a href="<?= $login_url ?>">Login With FaceBook</a>
<?php endif; ?>
<br>
<img style="width: 50px" src="<?= $picter ?>">
the code is working fine when i test is outside WordPress . my problem is after the log in is complicate the page redirect that i want is https://en.economarks.com/form but i don't get the user data and i am still not logged in but when i redirect to https://en.economarks.com/wp-content/themes/twentyseventeen/FormReg.php every thing is working fine any help?
</div>