title: ask for the re-authentication in api when logout from facebook
body: <p>I am using Facebook Open Graph (php) provided by facebook to fetch user's images. All is working fine. When user comes to my website and clicks on the facebook button, it is asking for the authentication first and then imports the user's images. Because of this process user automatically logs in the facebook.com as well. It is expected behavior.</p>
  
  <p>But after all this process, if user logs out from facebook.com, and then again clicks on the facebook button in my website, I believe my app shall ask for authentication but it does not ask for the authentication but provides the images from the user's facebook account.
  Please ask for more details If I was not clear.
  Thank you in advance.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Code:</p>
  
  <p>index.php</p>
  
  <pre><code>&lt;?php
       /**********************************************************************
       * Plugin Name: Facebook Plugin                                        *
       * Plugin URI: http://www.picpixa.com/                                 *
       * Version: 1.0                                                        *
       * Author: Ashish Shah                                                 *
       * Description: Plugin To Import Images From User's Facebook Account   *
       *              as well as post the image of personalized product to   *
       *              his/her facebook account                               *
       **********************************************************************/
      session_start();
      include_once '/home/picpixa/wp-config.php';
      include_once "fbmain.php";
      include_once "facebook.php";
  
      ini_set("display_errors",1);
  ?&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
          &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
          &lt;title&gt;Facebook Images&lt;/title&gt;      
          &lt;!-- Bootstrap --&gt;
          &lt;link href="css/bootstrap.css" rel="stylesheet"&gt;
          &lt;link href="css/style.css" rel="stylesheet"&gt;
  
          &lt;style&gt;
              .loader {
                  position: fixed;
                  left: 0px;
                  top: 0px;
                  width: 100%;
                  height: 100%;
                  z-index: 9999;
                  background: url('Images/page-loader.gif') 50% 50% no-repeat rgb(249,249,249);
              }
          &lt;/style&gt;
  
          &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"&gt;&lt;/script&gt;
          &lt;script type="text/javascript"&gt;
              $(window).load(function() {
                  $(".loader").fadeOut("slow");
              });
  
              function loader(){
                  $('#load').show();
              }
              /* function loadExistingImages(){
                  window.opener.$('#loader_img').show();
                  result=null;
                  window.opener.$('#fileupload').each(function () {
                      var that = this;
                      window.opener.$.getJSON(this.action, function (result) {
                          if (result &amp;&amp; result.length) {
                              window.opener.$(that).fileupload('option', 'done')
                                  .call(that, null, {result: result});
                              //console.log('ss='+$('.table-striped tbody').find('.btn-danger').length);
                              if(window.opener.$('.table-striped .files').find('.btn-danger').length&gt;0){
                                  window.opener.$('.coo-images-other-buttons').show();
                              }else{
                                  window.opener.$('.coo-images-other-buttons').hide();
                              }
                          }
                          window.opener.$('#loader_img').hide();
  
                          if (window.opener.$('.table-striped.files').children().length &gt; 0)
                          {
                              window.opener.$('.table_tagline').show();
                          }
                      });
                  });
              }*/
          &lt;/script&gt;
          &lt;script type="text/javascript"&gt;$('#load').hide();&lt;/script&gt;
      &lt;/head&gt;
  &lt;?php
          if(isset($_POST['copy']) &amp;&amp; $_POST['facebook'])
          {
              $imgArray = $_POST['facebook'];
              $current_user = wp_get_current_user();
  
              if(isset($current_user-&gt;ID) &amp;&amp; trim($current_user-&gt;ID)!='' &amp;&amp; trim($current_user-&gt;ID)!=0){
                  $extraSessionStr = 'usr-'.md5($current_user-&gt;ID).'/';
                  $userPicpixa = $current_user-&gt;ID;
              }else{
                  $sesstionId = session_id();
                  $userPicpixa = $sesstionId;
                  $extraSessionStr = $sesstionId.'/';
              }
  
              foreach ($imgArray as $img)
              {
                  //Getting a file name
                  $imgInfo = pathinfo($img); //This will become an array with keys ('dirname','basename','extension','filename')
                  $oriFileName = (string) uniqid("FB-");//"FB-image";
                  $imgExtension = "jpg";
  
                  //sometime facebook sends some odd extension including ? after the extension
                  //Ex. &lt;image path &amp; name&gt;.jpg?oh=dea6bece1e47875b65b9e3eb9299ea20&amp;oe=545564F2&amp;__gda__=1413855237_b5ab7de5ee45555ff6b87cbad003e3f4
  
                  //That is why giving static extension
  
                  $fileName = (string) $oriFileName.".".$imgExtension;//Creating a file name with extension
  
                  //Check wether the file is exists or not rename the file if exists
                  $i=1;
                  if(file_exists('/home/picpixa/server/php/files/'.$extraSessionStr.$fileName)){
                      while(file_exists('/home/picpixa/server/php/files/'.$extraSessionStr.$fileName)){
                          $fileName = (string) $oriFileName."(".$i.").".$imgExtension;
                          $i++;
                      }
                  }
  
                  //if (extension_loaded('imagick')){ //This condition is to check that imagick extension has been installed or not
                  //if( class_exists("Imagick") ){ //This condition is to check that imagick class exists or not or not
  
                  /*if ( !version_compare( phpversion( 'imagick' ), '2.2.0', '&lt;' ) )
                      die("Not a PHP version error");*/
  
  
  
                  // Read file content
                  $file_content = file_get_contents($img);
                  //Putting the main file into the directory
                  file_put_contents('/home/picpixa/server/php/files/'.$extraSessionStr.$fileName, $file_content);
  
                  /* To create thumbnail */
  
                  // Max vert or horiz resolution
                  $maxsize=80;
  
                  // create new Imagick object
                  $image = new Imagick($img); //"input_image_filename_and_location"
  
                  // Resizes to whichever is larger, width or height
                  if($image-&gt;getImageHeight() &lt;= $image-&gt;getImageWidth())
                  {
                      // Resize image using the lanczos resampling algorithm based on width
                      $image-&gt;resizeImage($maxsize,0,Imagick::FILTER_LANCZOS,1);
                  }
                  else
                  {
                      // Resize image using the lanczos resampling algorithm based on height
                      $image-&gt;resizeImage(0,$maxsize,Imagick::FILTER_LANCZOS,1);
                  }
  
                  // Set to use jpeg compression
                  $image-&gt;setImageCompression(Imagick::COMPRESSION_JPEG);
                  // Set compression level (1 lowest quality, 100 highest quality)
                  $image-&gt;setImageCompressionQuality(75);
                  // Strip out unneeded meta data
                  $image-&gt;stripImage();
                  // Writes resultant image to output directory
                  $image-&gt;writeImage('/home/picpixa/server/php/thumbnails/'.$extraSessionStr.$fileName); //"output_image_filename_and_location"
                  // Destroys Imagick object, freeing allocated resources in the process
                  $image-&gt;destroy();
              }
  ?&gt;
              &lt;script type="text/javascript"&gt;
  
                  window.opener.$('tbody.files').find('tr').remove();
                  //loadExistingImages();
                      var myVar;
                      if (/(MSIE\ [0-9]{1})/i.test(navigator.userAgent)) {
                          window.opener.$(window.opener.loadExistingFiles());
                          myVar = setTimeout(function(){
                              window.opener.$('tbody.files').find('tr .preview a[title="&lt;?php echo $fileName;?&gt;"]').click();
                          },1000);
                      }
                      else{
                          window.opener.$.when(window.opener.loadExistingFiles()).done(function(){
                              myVar = setTimeout(function(){
                                  window.opener.$('tbody.files').find('tr .preview a[title="&lt;?php echo $fileName;?&gt;"]').click();
                              },1000);
                          });
                      }
  
              &lt;/script&gt;
  &lt;?php
              echo "&lt;h2&gt;The selected images have been uploaded successfully.&lt;/h2&gt;";
              //echo "&lt;h3&gt;Please click on \"Proceed With Uploaded Images\" button to Proceed OR ";
              //echo "Click on the \"Upload More Images\" Button to upload more images.&lt;/h3&gt;";
  ?&gt;
              &lt;div class="modal-footer"&gt;
                  &lt;input type='button' name='continue' value='Upload More Images' class='btn btn-primary' onclick='loader(); window.location.href="https://www.picpixa.com/wp-content/plugins/create-own-object/plugin-facebook/index.php";'&gt;
                  &lt;!-- &lt;input type='button' name='closeWindow' value='Close' class='btn btn-primary' onClick="window.close();"&gt; --&gt;
              &lt;/div&gt;
  &lt;?php
              die();          
          }
          elseif (isset($_POST['copy']))
          {
              echo "&lt;h2&gt;You have not selected any image(s) to move.&lt;/h2&gt;&lt;br&gt;&lt;br&gt;";
              //echo "&lt;h3&gt;Please click on \"Close\" button to Close the window OR ";
              //echo "Click on the \"Upload Images\" Button to upload images.&lt;/h3&gt;";
  ?&gt;
              &lt;div class="modal-footer"&gt;
                  &lt;input type='button' name='continue' value='Upload Images' class='btn btn-primary' onclick='loader(); window.location.href="https://www.picpixa.com/wp-content/plugins/create-own-object/plugin-facebook/index.php";'&gt;
                  &lt;!-- &lt;input type='button' name='closeWindow' value='Close' class='btn btn-primary' onClick="window.close();"&gt; --&gt;
              &lt;/div&gt;
  &lt;?php
              die();
          }
  ?&gt;
      &lt;body&gt;
          &lt;div id="load" class="loader"&gt;&lt;/div&gt;
  &lt;?php 
          if(isset($_GET['logout']) &amp;&amp; $_GET['logout']=='yes'){
              $user = null;
              $facebook-&gt;logoutFromSite();
          }
  
          if (!$user){
  ?&gt;
              &lt;div id="wrap"&gt;
                  &lt;div class="header"&gt;
                      &lt;h4&gt;Facebook&lt;/h4&gt;
                      &lt;p&gt;Display Your Photo Stream&lt;/p&gt;
                  &lt;/div&gt;
                  &lt;div class="cl"&gt;&lt;/div&gt;
                  &lt;div id="middal_part"&gt;
                      &lt;div class="left_side"&gt;
                          &lt;img src="Images/fb.jpg"/&gt;
                      &lt;/div&gt;
                      &lt;div class="right_side"&gt;
                          &lt;a class="btn btn-primary" href="&lt;?= $loginUrl ?&gt;" onClick='loader()'&gt;Login&lt;/a&gt;&lt;br&gt;&lt;br&gt;
                          &lt;!-- &lt;button class="btn btn-primary close_window" type="button"  onClick="window.close();"&gt;Close&lt;/button&gt; --&gt;
                      &lt;/div&gt;
                      &lt;div class="cl"&gt;&lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  &lt;?php
          }// else { ?&gt;
              &lt;!--    &lt;div class="right_side"&gt;
                          &lt;a href="&lt;? //= $logoutUrl; ?&gt;" onClick='loader()'&gt;&lt;img src="Images/logout.png"&gt;&lt;/a&gt;
                      &lt;/div&gt; --&gt;
          &lt;?php //} ?&gt;
  
          &lt;!-- all time check if user session is valid or not --&gt;
  &lt;?php
          if ($user) {
  ?&gt;
              &lt;form method="post" action="index.php"&gt;
                  &lt;div class="container"&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"&gt;
                              &lt;div class="modal-body"&gt;
                                  &lt;div id='folderList'&gt;
  
                                  &lt;!-- Data retrived from user profile are shown here --&gt;
  &lt;?php
                                  $albums = $facebook-&gt;api("/me/albums");
                                  foreach($albums['data'] as $album){
                                      ?&gt;&lt;div class="baby_img"&gt;
                                              &lt;a href="#" onclick="loader();showAlbum('&lt;?php echo $album['id']; ?&gt;')"&gt;
                                                  &lt;img src="Images/folder.jpeg" style="width:150px !important; height:120px !important;"&gt;
                                                  &lt;div style="clear: both;"&gt;&lt;/div&gt;&lt;?php echo $album['name']; ?&gt;
                                              &lt;/a&gt;
                                  &lt;/div&gt;&lt;?php
                                  }
  ?&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
  
                  &lt;div id="fbhtmlImage"&gt;
                      &lt;!-- Album images are being loaded here. --&gt;
                  &lt;/div&gt;
                  &lt;!--&lt;div class="modal-footer" id="fbmodal-footer" &lt;?php if(!$showBtn){ ?&gt; style="display:none;"&lt;?php  } ?&gt; &gt;
                      &lt;input type='submit' name='copy' value='Copy Selected Files' class='btn btn-primary' onclick='loader()' /&gt;
                      &lt;input type='button' name='closeWindow' value='Close This Window' class='btn btn-primary' onClick="window.close();"&gt;
                  &lt;/div&gt;--&gt;
  
  
  
              &lt;/form&gt;
          &lt;?php } ?&gt;
  
          &lt;script type="text/javascript"&gt;
              function backToAlbums(){
                  $('#fbhtmlImage').hide();
                  $('#fbmodal-footer').hide();
                  $('#folderList').show();
              }
  
              function showAlbum(albumId){
                  $('#folderList').hide();
                  var fbhtml = '';
                  //fbhtml = document.write("&lt;a class='btn btn-primary' href='" + document.referrer + "'&gt;Back&lt;/a&gt;");
                  fbhtml += "&lt;div class='container'&gt;\
                      &lt;div class='row'&gt;\
                          &lt;div class='col-lg-12 col-md-12 col-sm-12 col-xs-12'&gt;\
                              &lt;div class='modal-body'&gt;\
                                  &lt;a class='btn btn-primary' href='javascript: void(0);' onClick='backToAlbums();'&gt;Back&lt;/a&gt;\
                              &lt;/div&gt;\
                              &lt;div class='clearfix'&gt;&lt;/div&gt;\
                          &lt;/div&gt;\
                      &lt;/div&gt;\
                  &lt;/div&gt;";
                  $.ajax({                    
                       type: "GET",
                       url: "fbphotos.php",
                       data: { albumId: albumId }
  
                      }).done(function(response) {
                          var response = jQuery.parseJSON(response );
                          var showBtn = false;
                          fbhtml += "&lt;div class='container'&gt;\
                              &lt;div class='row'&gt;\
                                  &lt;div class='col-lg-12 col-md-12 col-sm-12 col-xs-12'&gt;\
                                      &lt;div class='modal-body'&gt;";
  
                                          if(response['data'].length&gt;0)
                                          {
                                              for(var x=0; x&lt;response['data'].length; x++){
                                                  fbhtml += '&lt;div class="baby_img"&gt;';
                                                  fbhtml += '&lt;input type="checkbox" id="facebook_'+x+'" name="facebook[]" value="'+response['data'][x]['source']+'" class="styled" /&gt;';
                                                  fbhtml += '&lt;img src="'+response['data'][x]['source']+'" class="img-responsive" style="width:100px !important; height:100px !important;" /&gt;';
                                                  fbhtml += '&lt;/div&gt;';
                                                  showBtn = true;
                                              }
                                          }
                                          else
                                          {
                                              fbhtml += '&lt;div class="baby_img"&gt;';
                                              fbhtml += 'There are no image(s) in this album.';
                                              fbhtml += '&lt;/div&gt;';
                                          }
  
                                      fbhtml += "&lt;/div&gt;\
                                      &lt;div class='clearfix'&gt;&lt;/div&gt;\
                                      &lt;div class='modal-footer'&gt;";
                                      if(showBtn == true)
                                      {
                                          fbhtml += "&lt;input type='submit' name='copy' value='Copy Selected Files' class='btn btn-primary' onclick='loader()' /&gt;";
                                      }
  
                                  /*  fbhtml += "&lt;input type='button' name='closeWindow' value='Close This Window' class='btn btn-primary' onClick='window.close();'&gt;\
                                      &lt;/div&gt;\
                                  &lt;/div&gt;\
                              &lt;/div&gt;\
                          &lt;/div&gt;";*/
                                      fbhtml += "&lt;/div&gt;\
                                      &lt;/div&gt;\
                                  &lt;/div&gt;\
                              &lt;/div&gt;";
  
                          //$('#fbhtmlImage').html(''); // does blank
                          //alert($('#fbhtmlImage').html()); //gets images as alert($('#fbhtmlImage').html()); 
                          $('#fbhtmlImage').html(fbhtml);
                          $('#fbhtmlImage').show();
                          //$('#fbmodal-footer').show();
  
                          //alert("Div filled");
                          $(".loader").fadeOut("slow");
                  });
              }
          &lt;/script&gt;
  
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>