CSRF state token does not match one provided FB PHP SDK 3.1.1 Oauth 2.0

I had a similar issue last week, and tracked it down to the state field being overwritten by multiple calls to getLoginUrl(). Each time you call getLoginUrl(), a new state token is generated in the SDK and stored in the $_SESSION (it’s just a random value), so if you call it twice and the user uses the first link to log in, the second call will have reset the SDK’s internal state token, and you will get this error in your logs.

The SDK looks for the same state token in the URL coming back after Facebook authorizes the user and redirects them back to your site, and if it doesn’t match it will log this error (here’s a link to the source).

Leave a Comment