title: Facebook PHP SDK 5 :: API 2.4 :: Cross-site request forgery validation failed. Required param "state" missing
body: <p>I did a very simple PHP script, just to try to login via Facebook and get an accessToken. But when I try the following code, I get an Exception from the SDK : « Cross-site request forgery validation failed. Required param "state" missing. ».</p>
  
  <p>Here is my code :</p>
  
  <pre><code>require_once __DIR__ . '/facebook-sdk-v5/autoload.php';
  session_start();
  
  $fb = new Facebook\Facebook([
      'app_id' =&gt; '{my-own-app-id}',
      'app_secret' =&gt; '{my-own-app-secret}'
  ]);
  
  // Check to see if we already have an accessToken ?
  if (isset($_SESSION['facebook_access_token'] )) {
      $accessToken = $_SESSION['facebook_access_token'];
      echo "Horray we have our accessToken:$accessToken&lt;br /&gt;\n";
  
  } else {
      // We don't have the accessToken
      // But are we in the process of getting it ? 
      if (isset($_REQUEST['code'])) {
          $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)) {
                // Logged in!
                $_SESSION['facebook_access_token'] = (string) $accessToken;
  
                // Now you can redirect to another page and use the
                // access token from $_SESSION['facebook_access_token']
  
                echo "Finally logged in! Token:$accessToken";
          }           
      } else {
          // Well looks like we are a fresh dude, login to Facebook!
          $helper = $fb-&gt;getRedirectLoginHelper();
          $permissions = ['email', 'user_likes']; // optional
          $loginUrl = $helper-&gt;getLoginUrl('http://mywebsite.com/myapp/index.php', $permissions);
  
          echo '&lt;a href="' . $loginUrl . '"&gt;Log in with Facebook!&lt;/a&gt;';
      }
  
  }
  
  exit;
  </code></pre>