title: Logout with Facebook PHP SDK v5
body: <p>I'm using Facebook SDK v5 and I can login with this script, while logging in I created a cookie and if I try to logout by clearing that cookie is not possible!</p>
  
  <p>this is my Login Script</p>
  
  <pre><code>&lt;?php
  require_once __DIR__ . '/src/Facebook/autoload.php';
  require_once $_SERVER['DOCUMENT_ROOT'].'/fbloging/helper/helper.php';
  $fb = new Facebook\Facebook([
  'app_id' =&gt; '__MY_APP_ID__',
  'app_secret' =&gt; '__MY_APP_SECRET__',
  'default_graph_version' =&gt; 'v2.5'
  ]);
  
  $helper = $fb-&gt;getJavaScriptHelper();
  
  try {
  $accessToken = $helper-&gt;getAccessToken();
  } catch(Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e-&gt;getMessage();
  } catch(Facebook\Exceptions\FacebookSDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e-&gt;getMessage();
  }
  
  if (isset($accessToken)) {
  $fb-&gt;setDefaultAccessToken($accessToken);
  
  try {
  
  $requestProfile = $fb-&gt;get("/me?fields=name,email,id,picture.width(800).height(800),cover.width(300).height(175)");
  $profile = $requestProfile-&gt;getGraphNode()-&gt;asArray();
  } catch(Facebook\Exceptions\FacebookResponseException $e) {
  // When Graph returns an error
  echo 'Graph returned an error: ' . $e-&gt;getMessage();
  } catch(Facebook\Exceptions\FacebookSDKException $e) {
  // When validation fails or other local issues
  echo 'Facebook SDK returned an error: ' . $e-&gt;getMessage();
  }
  
  
  $query = "SELECT * FROM `users` WHERE `user_id`='".$profile['id']."' AND `email`='".$profile['email']."'";
  $result = $db-&gt;query($query);
  $fr = mysqli_fetch_assoc($result);
  if(mysqli_num_rows($result)&gt;0){
  if($fr['profile']==1){
  set_user_cookie($profile['name'],$profile['id'],$profile['picture']['url'],$profile['email'],$profile['cover']['source']);
  header('location: ../home.php');
  }else{
  set_user_cookie($profile['name'],$profile['id'],$profile['picture']['url'],$profile['email'],$profile['cover']['source']);
  header('location: ../complete-profile.php');
  }
  
  }else{
  $name = $profile['name'];
  $id = $profile['id'];
  $email = $profile['email'];
  $result = $db-&gt;query("INSERT INTO `users`(`user_id`, `email`, `user_name`) VALUES ('$id','$email','$name')");
  if($result){
  set_user_cookie($name,$id,$profile['picture']['url'],$email,$profile['cover']['source']);
  header('location: ../complete-profile.php');
  }else{
  echo 'Something Went Wrong';
  }
  }
  
  // setcookie('user',$profile['name']."~".$profile['id']."~".$profile['picture']['url']."~".$profile['email'], time()+3600+2,"/");
  // header('location: ../');
  exit;
  } else {
  echo "Unauthorized access!!!";
  exit;
  }
  </code></pre>
  
  <p>This is function to set COOKIE</p>
  
  <p><strong>helper.php</strong></p>
  
  <pre><code>// Set cookie
  function set_user_cookie($name, $id, $pro, $email,$cover){
  $string=$name."~".$id."~".$pro."~".$email."~".$cover;
  setcookie('udet',$string, time()+3600*2*24,"/");
  }
  </code></pre>
  
  <p>I'm using Cookie to store some user data to display that details when they are logged in in a file. I needed user can access that page when that COOKIE is set like this</p>
  
  <p><strong>complete-profile.php</strong></p>
  
  <pre><code>require_once 'helper/helper.php';
  if (isset($_COOKIE['udet'])) {
  $user = explode("~",$_COOKIE['udet']);
  $name =  $user[0];
  $id = $user[1];
  $pic = $user[2];
  $email = $user[3];
  $cover = $user[4];
  }else{
  header('Location : index.php');
  }
  </code></pre>
  
  <p>and I set a link to logout, in that logout file I just deleting that cookie like this</p>
  
  <p><strong>logout.php</strong></p>
  
  <pre><code>&lt;?php
  unset($_COOKIE['udet']);
  header('Location: index.php')
  ?&gt;
  </code></pre>
  
  <p>but after deleting also I can access those user data and that facebook account is not logged out!</p>
  
  <p>I searched for this answer but I didn't find any proper answer on the web!</p>
  
  <p>I need to logout the user when they click logout URL (Logout URL access logout.php)</p>
  
  <p>please help me</p>