I don’t understand the code that comes after “The following PHP example demonstrates the server-side flow with CSRF protection in one self-contained example:” at http://developers.facebook.com/docs/authentication/ i.e Why is it needed?
Why session_start(); is needed? I don’t understand where the work with the session begins or ends.
How does the CSRF protection work?
Why access token is not returned right after user login?
I don’t understand the code that comes after The following PHP example demonstrates the
Share
You call
session_start()once at the top of your script, before anything it printed out.After that you have access to the
$_SESSIONarray. This allows you to store values like$_SESSION['state']from one page call to another.The code in the example shows a CSRF protection. The first time you call tt stores a random value in the session and compares it afterwards.
Read more about php sessions.
Update Script with comments. If you have a look at the picture above the script… I “marked” some points from there.