php如何使用Facebook创建管理面板

php如何使用Facebook创建管理面板

问题描述:

I'm trying to create my admin panel in my website with Facebook. So I'd like to view via PHP if the Facebook user id is mine or of a friend. until i was just wondering only MY user id, all right. The admin panel functioned perfectly. But if in the "if" i add another id, nobody can view the admin panel neither me! (so if the user logged-in is me OR my friend let us pass, else block it and exit with a message where explain that the user don't have necessary permissions to view the admin panel.) How to do what i want to do? Thanks

    $facebook = new Facebook($config);
    $user_id = $facebook->getUser();

if($user_id) {

  // We have a user ID, so probably a logged in user.
  // If not, we'll get an exception, which we handle below.
  try {
    if (($user_id!="123456789") || ($user_id!="987654321"))
        exit("no permissions");
    else
    {
       // ...todo..
     }
   // etc... etc...

As per my comment, this is a simple logic error: if the user id is 987654321 the 1st part of the check will fail, and vise versa. A possible solution for you:

$admin_users=array('123456789', '987654321');
if(!in_array($user_id, $admin_users){
exit("no permissions");
else
{
   // ...todo..
 }