Facebook login error in mobile browser
<p>I'm using API Facebook to login on my website but.. login from desktop browser works fine, login from mobile browser return an error.</p>

<p>The error message from mobile browser is:
<code>Facebook SDK returned an error: Cross-site request forgery validation failed. Required param "state" missing from persistent data.</code></p>

<p>In login page I used this code to generate the link to facebook
(I'm using the Facebook PHP SDK)</p>

<p><strong>login</strong></p>

<pre><code>    if(!session_id()) {
        session_start();
    }
    $fb = new Facebook\Facebook([
      'app_id' =&gt; APP_ID,
      'app_secret' =&gt; APP_SECRET,
      'default_graph_version' =&gt; 'v2.2'
    ]);

    $helper = $fb-&gt;getRedirectLoginHelper();

    $permissions = ['email']; // Optional permissions
    $loginUrl = $helper-&gt;getLoginUrl(SERVER_CALLBACK, $permissions);

    $facebook = htmlspecialchars($loginUrl);
</code></pre>

<p>This is the callback</p>

<p><strong>callback</strong></p>

<pre><code>    if(!session_id()) {
        session_start();
    }
    $fb = new Facebook\Facebook([
        'app_id' =&gt; APP_ID,
        'app_secret' =&gt; APP_SECRET,
        'default_graph_version' =&gt; 'v2.2',
        'persistent_data_handler'=&gt;'session'
    ]);

    $helper = $fb-&gt;getRedirectLoginHelper();

    try {
        $accessToken = $helper-&gt;getAccessToken();
    } catch(Facebook\Exceptions\FacebookResponseException $e) {
        // When Graph returns an error
        echo 'Graph returned an error: ' . $e-&gt;getMessage();
        exit;
    } catch(Facebook\Exceptions\FacebookSDKException $e) {
        // When validation fails or other local issues
        echo 'Facebook SDK returned an error: ' . $e-&gt;getMessage();
        exit;
    }

    if (! isset($accessToken)) {
        if ($helper-&gt;getError()) {
            header('HTTP/1.0 401 Unauthorized');
            echo "Error: " . $helper-&gt;getError() . "\n";
            echo "Error Code: " . $helper-&gt;getErrorCode() . "\n";
            echo "Error Reason: " . $helper-&gt;getErrorReason() . "\n";
            echo "Error Description: " . $helper-&gt;getErrorDescription() . "\n";
        } else {
            header('HTTP/1.0 400 Bad Request');
            echo 'Bad request';
        }
        exit;
    }

    // Logged in

    // The OAuth 2.0 client handler helps us manage access tokens
    $oAuth2Client = $fb-&gt;getOAuth2Client();

    // Get the access token metadata from /debug_token
    $tokenMetadata = $oAuth2Client-&gt;debugToken($accessToken);

    // Validation (these will throw FacebookSDKException's when they fail)
    $tokenMetadata-&gt;validateAppId(APP_ID);
    // If you know the user ID this access token belongs to, you can validate it here
    $tokenMetadata-&gt;validateExpiration();

    if (! $accessToken-&gt;isLongLived()) {
        // Exchanges a short-lived access token for a long-lived one
        try {
            $accessToken = $oAuth2Client-&gt;getLongLivedAccessToken($accessToken);
        } catch (Facebook\Exceptions\FacebookSDKException $e) {
            echo "&lt;p&gt;Error getting long-lived access token: " . $helper-&gt;getMessage() . "&lt;/p&gt;\n\n";
            exit;
        }
    }
</code></pre>

<p>I'm wonder because everything is working in desktop navigation, but using a mobile browser something is going wrong.</p>