44 thoughts on “Best Practice for Facebook Login on Website Using PHP and JS – 2

  1. Why can't you just upload the complete demo or working website instead of one which we have to edit
    at least we can compare with each other to figure out what's the matter with the error, no?

  2. my name doesn't show on index page and the button remains. Means session doesnt activate. I have added start_session on the index page. I am not sure where i could be wrong as i rechecked. Would it be because of the version of facebook_sdk? becaz the one shown in the video is v4 which is no longer available on github so i downloded php-graph-sdk-5.5 and used that instead. A kind request to help me please.

  3. what an amazing video ! I am now trying to make it and wish me luck 🙂
    anyway, I would like to ask you two "unnecessary" questions about XAMPP and PHP you used. Well, I am just curious about it, you obviously used localhost, but why it showed only "website.com" as if it is really an active website instead of localhost/index.html?

    and the last but not least, I planned to use that login with some features, such as you may change your profile picture (not only welcome "name") and they may comment to some articles that my website has already had with their own name (they would not be possible to either comment or like if they haven;t logged-in yet)

    is that possible to do, sir? or perhaps you could tell me what is the name of PHP to construct those features. Thank you so much. Sorry for the long comment. Once again, Your videos are amazing, please continue making another awesome PHP video! Good luck!

  4. I would like to know if there is a way to capture once email address. I
    am using this as a login in my web application but unable to
    fetch/capture the email address of the user. I require the email address
    to send order confirmation , invoice and stuff to the user once a
    service has been booked.And yes, I would also like to customize the size of the button.

  5. Hello Sohaib,

    is some kind of ID generated to the user when he logs in first time ? Will he have the same ID everytime he logs in again ?
    I need to store user ID into mySQL – e.g. I am making web with orders, after user logs in I need to show all his orders based on his ID.

  6. Hello Sir, I have followed your videos about the Facebook app tutorials, those are excellent. But now I am facing these issue, can you help me with the bugs please?

    [Sun Jul 31 09:27:13 2016] ::1:50102 [500]: /fbapp/login-callback.php – Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.' in /Users/maddie/NetBeansProjects/TudouPHP/fbapp/src/Facebook/Authentication/AccessToken.php:156
    Stack trace:
    #0 /Users/maddie/NetBeansProjects/TudouPHP/fbapp/src/Facebook/Authentication/AccessToken.php(156): DateTime->__construct()
    #1 /Users/maddie/NetBeansProjects/TudouPHP/fbapp/src/Facebook/Authentication/AccessToken.php(57): FacebookAuthenticationAccessToken->setExpiresAtFromTimeStamp(1470042000)
    #2 /Users/maddie/NetBeansProjects/TudouPHP/fbapp/src/Facebook/Authentication/OAuth2Client.php(247): FacebookAuthenticationAccessToken->__construct('EAAP68R9rwzkBAO… in /Users/maddie/NetBeansProjects/TudouPHP/fbapp/src/Facebook/Authentication/AccessToken.php on line 156

  7. App Not Setup: This app is still in development mode, and you don't have access to it. Switch to a registered test user or ask an app admin for permissions.

    How to solve this ( My App is already public)

  8. I there a way user who logged in via facebook can be added into my user database? The reason I am asking is that I have level of users that have access to specific content.

  9. great tutorial Sohaib thank you, just a question. Imagine i do a login within other page (other project in same domain ) how can this script check if i'am already logged in? has this something to do with the Valid OAuth redirect URIs ? if so, how can i accomplish this?

  10. Hey Roomi. Thanks for great videos.

    I have a question about how can Post/Share using this script and using same Session/Cookies to avoid login after user destroy the session. Can you make an example? It will help us allot.

    I have already done to keep user logged for 5 days using Cookies as you done in this video.

    But how we can post/share using the same session/cookies?

    Thanks in advance man !!

  11. Hello Okay'm from Brazil and congratulations for the tutorial, but I friend I found a problem when I click the button it connects asks authorizations and when will drive to put on the screen the text he gives this error .– Facebook SDK returned an error : Failed to connect to graph.facebook.com port 443: Connection refusedUnauthorized access !!! – And I have put in face authorizations and type in the same way.

    $helper = $fb->getJavaScriptHelper();

    try {
    $accessToken = $helper->getAccessToken();
    } catch(FacebookExceptionsFacebookResponseException $e) {
    // When Graph returns an error
    echo 'Graph returned an error: ' . $e->getMessage();
    } catch(FacebookExceptionsFacebookSDKException $e) {
    // When validation fails or other local issues
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    }

    if (isset($accessToken)) {
    $fb->setDefaultAccessToken($accessToken);

    try {

    $requestProfile = $fb->get("/me?fields=public_profile,email");
    $profile = $requestProfile->getGraphNode()->asArray();
    } catch(FacebookExceptionsFacebookResponseException $e) {
    // When Graph returns an error
    echo 'Graph returned an error: ' . $e->getMessage();
    } catch(FacebookExceptionsFacebookSDKException $e) {
    // When validation fails or other local issues
    echo 'Facebook SDK returned an error: ' . $e->getMessage();
    }

    setcookie('name', $profile['name'], time() + (3600 *2), "/");
    header('location: ../');
    exit;
    } else {
    echo "Unauthorized access!!!";
    exit;
    }

  12. Sohaib i was following your tutorial its really amazing but i have a issue when i clicked the login icon so this eror has came "Given URL is not allowed by the Application configuration: One or more of the given URLs is not allowed by the App's settings. It must match the Website URL or Canvas URL, or the domain must be a subdomain of one of the App's domains." Please suggest me what i do for solve this issue????

Leave a Reply

Your email address will not be published. Required fields are marked *