I believe I have read almost all if not all the related posts, but I still can't find my answer.
On client side I get the user to login and send user id and access token to server. Then server use facebook->getUser()
to check if the sent userid really belong to him, if so I add him to my database and register him. similar to this question
Facebook Login: How to combine JavaScript with PHP SDK?
except facebook->getUser()
keep returning 0. I have look through A LOT of questions related to that too, but I just cant find my answer. No problem with client side though, user can log in and give authority, it generate the correct userid and a token.
I am currently using localhost to test everything.
php:
<?php
require 'facebook/src/facebook.php';
$uid = $_POST['userid'];
$token = $_POST['accessToken'];
$facebook = new Facebook(array(
'appId' => 'XXXXXXXXXXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXX',
));
// Get User ID
$user = $facebook->getUser();
if($user==$uid){
//codes here
My question is similar to the following posts but it didnt get any answer Facebook API: Login using JavaScript SDK then checking login state with PHP
additional info: the reason why I want to use PHP sdk too is because, I dont want people to use someone else's fb userID to send request to my server 'pretending' to be another person