Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1079091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:49:04+00:00 2026-05-16T21:49:04+00:00

I am a novice in Facebook development and PHP. I just started today and

  • 0

I am a novice in Facebook development and PHP. I just started today and I would like to know what the following code snippet does,

<?php

define('FACEBOOK_APP_ID', '123423');  
define('FACEBOOK_SECRET', '3eesewee3e');  

function get_facebook_cookie($app_id, $application_secret) {  
  $args = array();  
  parse_str(trim($_COOKIE['fbs_' . $app_id], '\\"'), $args); //Why??  
  ksort($args);  
  $payload = '';  
  foreach ($args as $key => $value) {        
    if ($key != 'sig') {//Why checking not equals to 'sig'  
      $payload .= $key . '=' . $value;  
    }  
  }  
  if (md5($payload . $application_secret) != $args['sig']) {//why is this checking  
    return null;  
  }  
  return $args;  
}  

$cookie = get_facebook_cookie(FACEBOOK_APP_ID, FACEBOOK_SECRET);  

?>

I kind of understood the PHP functions and their usage. I would like to know why is it done this way?

I would like to know the explanations for the lines with comments //why. I am kind of not so sure whats going to and fro during this communication and why are we doing these kind of checking etc.

Thanks for your time.

Regards,
Abhishek

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T21:49:04+00:00Added an answer on May 16, 2026 at 9:49 pm

    The first queried line is filling $args with keys/values from the cookie.

    The second queried line is in a loop of the keys of $args. It’s ignoring 'sig' because this is a signature and is not going to be hashed.

    The third queried line checks that the hash of the payload matches the signature.

    Basically, what this code is doing is parsing the cookie, sorting the keys into a standard order, taking a hash of the sorted keys and comparing that hash with the signature. If the signature doesn’t match the hash then the cookie has been tampered with.

    The $args array needs to be sorted with a standard sorting function, because the order of the data affects the hashed value.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
I would simply like to know if its possible to give images an ALT
Here's my code for my Facebook share link: <a href=<%= HttpUtility.UrlPathEncode(http://www.facebook.com/sharer.php?u=http://www.apoads.com+ Request.Url.PathAndQuery) %> title=Share
I am going over/studying the facebook code that was leaked in 2007, I notice
As I'm a novice, I started learning python by writing simple programs using python
I'm trying to develop a Facebook app on Heroku with PHP. I set up
i've created a facebook Application today for my website i'm requesting access_token through javascript
I'm having issues with the Facebook like button on my pages. On some pages
How to create flashing title effect like facebook? Means, when you are chatting with
I'm trying to get just a piece of information from Facebook, but I don't

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.