Guide to Writing PHP login with Facebook

To do write code to sign in with Facebook, you need to have APP ID and APP SECRET.


To use this app you need to download the SDK Facebook: http://developers.facebook.com/docs/reference/php/download/
Refer to the API documentation of Facebook:
Put the following code to PHP files to be processed log
  1. <? Php
  2. require 'facebook / facebook.php';
  3. $ FbPermissions = 'email, publish_stream, user_photos';
  4. $ Facebook = new Facebook (array (
  5. 'AppID' => '510685512391982',
  6. 'Secret' => '76ef9a5f323613670fe1f1d0f1f0dffd'
  7. 'FileUpload' => true,
  8. 'Cookie' => true
  9. ));
  10. $ User = $ facebook-> getUser ();
  11. if ($ user)
  12. {
  13.      tRY
  14.      {
  15.          $ User_profile = $ facebook-> api ( '/ me');
  16.          if (! empty ($ user_profile))
  17.          {
  18.              $ User_id = $ user_profile [ 'id'];
  19.              // The processing your login here offline
  20.          }
  21.      }
  22.      catch (FacebookApiException $ e)
  23.      {
  24.          $ User = null;
  25.      }
  26. }
  27. else
  28. {
  29.      $ LoginUrl = $ facebook-> getLoginUrl (array ( 'scope' => $ fbPermissions));    
  30. }
  31. ?>
  32. <Div class = "sign-in-bound">
  33.      <H4 class = "subtitle"> </ h4>
  34.          <P> <b> Click the button below to log in with your Facebook account. Your account will be created automatically after the first login without registration. </ B> </ p>
  35. <br clear="all">
  36.          <Div align = "center"> <a href="<?php echo $loginUrl;?> "> <img src =" skins / news / images / loginfacebook.png "> </a> </ div>
  37. <br clear="all">
  38. <P>
  39. <B> You can also log in with an account registered in Goccuoi.net. If you do not have
  40. account, <a href="dang-ky.html" </a> style="text-decoration:underline"> register here. </ b> </ p>
  41. <Div class = "log-input" style = "margin-top: 18px;">
  42. <Form name = "SignInForm" method = "post">
  43. <Div>
  44. <Label for = "user_id"> Name </ label> <span class = "required"> * </ span> </ div>
  45. <Input name = "user_id" type = "text" id = "user_id" class = "input">
  46. <Div> <label for = "password"> Password </ label> <span class = "required"> * </ span> </ div>
  47. <Input name = "password" type = "password" id = "password" class = "input">
  48. <Div>
  49. <Input name = "save_password" type = "checkbox" id = "save_password">
  50. <Label for = "save_password"> Automatically login next time </ label>
  51. </ Div>
  52. <Div style = "margin-left: -4px; margin-top: -10px;">
  53. <Input class = "search-button" type = "submit" value = "Login">
  54. Forgot your password <a href="quen-mat-khau.html"> </a>
  55. </ Div>
  56. </ Form>
  57. </ Div>
  58. </ Div>
If you have any questions, please comment down below for inquiries
Previous
Next Post »

1 comments:

Write comments
creatwe
AUTHOR
April 27, 2016 delete

Thank you for your share, its very important for me..

Reply
avatar