Some one help me to provide working fblogin script.

Thanks and Regards.

Dani AI

Generated

raised a request for a working FB login. and were correct to point toward the official SDK and the Facebook login flow; the notes below condense what is actually needed to get a reliable PHP implementation, a tiny callback example, and common failure points to check.

Essential checklist:

  1. Create a Facebook App and record the App ID and App Secret. Configure the exact OAuth redirect URI (protocol, host, path must match).
  2. Install the SDK via Composer or call the Graph endpoints directly. Ensure PHP has cURL and OpenSSL enabled.
  3. Build the login URL with minimal scope (e.g., email), a randomly generated state token saved in session, and the app_id + redirect_uri.
  4. On callback, verify state matches the session value, then exchange the returned code server-side for an access token. Use that token to request id,name,email (or the fields required).
  5. Map the Facebook identity to a local account, create a server-side session, and never expose the App Secret in client-side code.
  6. Move the app out of development mode and request review for any non-basic permissions before expecting general users to log in.

Minimal PHP callback outline (replace placeholders and use production-grade HTTP handling):

session_start();

if (!isset($_GET['code']) || !isset($_GET['state']) || $_GET['state'] !== $_SESSION['fb_state']) {
    exit('Invalid login attempt');
}

$code = $_GET['code'];
$appId = 'APP_ID';
$appSecret = 'APP_SECRET';
$redirect = 'https://example.com/fb-callback.php';

$tokenUrl = 'https://graph.facebook.com/oauth/access_token?client_id='
  . $appId . '&redirect_uri=' . urlencode($redirect)
  . '&client_secret=' . $appSecret . '&code=' . $code;

$resp = json_decode(file_get_contents($tokenUrl), true);
$accessToken = $resp['access_token'] ?? null;
$me = json_decode(file_get_contents('https://graph.facebook.com/me?fields=id,name,email&access_token=' . $accessToken), true);

Troubleshooting & security tips: common problems are redirect_uri mismatches, app still in dev mode (only admins/testers allowed), missing server TLS/cURL support, and requesting permissions that require review. Store secrets in environment variables, use HTTPS, validate tokens server-side, and enable detailed logging for the token exchange step.

Recommended Answers

All 3 Replies

Nobody is just going to do all your work for you. We come here to help people solve coding problems, not to act as code-monkeys for people who can't be bothered to do the work/research themselves.

I suggest you start by reading up on the . It has all the functionality required for this. Then there are also a lot of tutorials out there that help deal with these topics.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.