简体   繁体   中英

Facebook Login from external site

I have Facebook app in my site. When we integrate Facebook, it will leads to facebook login page everytime,but i want to login facebook from mysite. I will give separate login form for facebook, when we enter the facebook crendential in mysite login, it will login to facebook without asking facebook login page. Is it possible to do? I try the following curl function to do but not succeed

<?php

$EMAIL      = "fb_user_email";
 $PASSWORD   = "password";

  function cURL($url, $header=NULL, $cookie=NULL, $p=NULL)
  {
      $ch = curl_init();
      curl_setopt($ch, CURLOPT_HEADER, $header);
      curl_setopt($ch, CURLOPT_NOBODY, $header);
      curl_setopt($ch, CURLOPT_URL, $url);
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($ch, CURLOPT_COOKIE, $cookie);
      curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
      curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
      if ($p) {
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $p);
       }
       $result = curl_exec($ch);
       if ($result) {
          return $result;
        }
        else {
          return curl_error($ch);
        }
        curl_close($ch);
    }

$a = cURL("https://login.facebook.com/login.php?login_attempt=1",true,null,"email=$EMAIL&pass=$PASSWORD");
preg_match('%Set-Cookie: ([^;]+);%',$a,$b);
$c = cURL("https://login.facebook.com/login.php?login_attempt=1",true,$b[1],"email=$EMAIL&pass=$PASSWORD");
preg_match_all('%Set-Cookie: ([^;]+);%',$c,$d);
for($i=0;$i<count($d[0]);$i++)
$cookie.=$d[1][$i].";";


echo cURL("http://graph.facebook.com/oauth/authorize?client_id=APP_IDredirect_uri=APP_REDIRECT_URL&display=touch&scope=publish_stream, user_checkins, publish_checkins, offline_access",null,$cookie,null);
?>

Please help me to do. This is my task

Thanks in advance

Facebook does not allow direct login from third party application. One has to use facebook website for authentication.

It gives added security as the user credentials are not shared with third party applications but only facebook.

No, it isn't possible.

A glance at the Facebook sites shows something that appears to be CSRF protection in the source code for the login form. So you can't have a form on your own site pointing at theirs.

Using cURL in the way you appear to be trying to wouldn't work either, because you wouldn't be able to set the cookies that Facebook sends on the user's browser as you couldn't associate them with a different domain.

In either case, expecting people to enter their login credentials for another site on yours is, at best training them to be unsafe with their passwords. (Not that facebook is any better with their constant attempts to get my email password via "friend finder").

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM