title: FB share loads different image than og property provide
body: <p>I researched a lot about FB share issues but yet haven't resolved mine. 
  I think I even have found the problem in these posts-
  <a href="https://stackoverflow.com/a/26714882/5348972">https://stackoverflow.com/a/26714882/5348972</a>
  <a href="https://stackoverflow.com/a/35653463/5348972">https://stackoverflow.com/a/35653463/5348972</a></p>
  
  <p>My website contains a basic login system where if session is set -> display page else redirect to login page. So when I provide static og data to <code>&lt;head&gt;</code> , example-</p>
  
  <pre><code>&lt;meta property="og:image"content="http://example.com/images/loginPageCarausel/unnamed.png" /&gt;
          &lt;meta property="og:title" content="Some Title" /&gt;
          &lt;meta property="og:url" content="http://example.com" /&gt;
          &lt;meta property="og:description" content="No Description" /&gt;
          &lt;meta property="og:image:type" content="image/jpeg" /&gt;
          &lt;meta property="og:image:width" content="400" /&gt;
          &lt;meta property="og:image:height" content="300" /&gt;
  </code></pre>
  
  <p>Everything works fine. Post is shared with specified image because this part of <code>&lt;head&gt;</code> is common whether session is set or unset. However, when I change the header to this, </p>
  
  <pre><code>&lt;?php
          include_once 'includes/functions.php';
          $pg = getPageName('pages.php');
          if($pg) {
              if(isset($_GET['poll'])) {
                  $i = $_GET['poll'];
                  if(class_exists('Polls') &amp;&amp; class_exists('FilesUpload')) {
                      $vip_poll = Polls::getPollDataById(POST_TBL, $i);
                      $title = $vip_poll-&gt;question;
                      $gen = $vip_poll-&gt;poll_genre;
                      $vip_pollOwnersId = $vip_poll-&gt;user_id;
                      $media_files = FilesUpload::getMediaFiles(MED_TBL, $i, $vip_pollOwnersId);
                      $f_type = $media_files-&gt;file_type;
                      $f = $media_files-&gt;file_name;
                      $img_ext_array = array('jpg', 'gif', 'jpeg', 'png');
                      if (in_array($f_type, $img_ext_array)) {
                          $analysis = Polls::select_all_from_graph_page_data(GP_DATA_TBL, $vip_pollOwnersId, $i);
                          if($analysis != false) {
                              if (!empty($analysis)) {
                                  $analysis_data = $analysis-&gt;data;
                                  if (strlen($analysis_data) &gt; 300) {
                                      $analysis_data = substr($analysis_data, 0, 300) . "...";
                                  }
                                  $analysis = $analysis_data; ?&gt;
  &lt;meta property="fb:app_id" content="1775**************"&gt;
          &lt;meta property="og:image" content="http://www.example.com/&lt;?=$f?&gt;" /&gt;
          &lt;meta property="og:title" content="&lt;?=$title?&gt;" /&gt;
          &lt;meta property="og:url" content="http://example.com/pages.php?vip_poll=&lt;?=$i?&gt;&amp;genre=&lt;?=$gen?&gt;" /&gt;
          &lt;meta property="og:description" content="&lt;?=$analysis_data?&gt;" /&gt;
          &lt;meta property="og:image:type" content="image/jpeg" /&gt;
          &lt;meta property="og:image:width" content="400" /&gt;
          &lt;meta property="og:image:height" content="300" /&gt;
  
            &lt;?php                  }
                          }
                      }
  
                  }
              }
          }
  
          ?&gt;
  </code></pre>
  
  <p>In this case FB crawler finds one of the image of login page and FB debugger issues various og properties missing. I suspect this happens because the ajax request pages redirects FB crawler to login page because its session is never set. I have already read this page</p>
  
  <pre><code>https://developers.facebook.com/docs/sharing/webmasters/crawler
  </code></pre>
  
  <p>and tried solving this issue with HTACCESS and added this few rules in my htaccess file</p>
  
  <pre><code>RewriteCond %{HTTP_USER_AGENT} ^facebookexternalhit
  RewriteRule ^(.*)$ ogtags.php?$1 [L,QSA]
  </code></pre>
  
  <p>But it did not helped me either. I don't know much about htaccess coding but I wanted to know can these lines let crawler access contents even when its not logged in. If not then do I need to change my login logic (which perhaps is not a good idea). If there's better ways please elaborate. </p>
  
  <p>I also tried changing the meta tags using jquery but that didn't worked either. </p>
  
  <p>My question is how do I redirect FB crawler to the correct url specified which is <code>&lt;meta property="og:image" content="http://www.example.com/&lt;?=$f?&gt;" /&gt;</code>? I can also redirect crawler to another page through htaccess</p>
  
  <pre><code>RewriteCond %{HTTP_USER_AGENT} facebookexternalhit [NC,OR] 
  </code></pre>
  
  <p>But then I would need to send post id to run queries and update meta tags dynamically in that redirected page. I don't know how that can be done (sending an id to two different urls at same time). My second question is I read in FB that it scrapes info only when the post is shared. I tried to change the meta tags both by jquery and php and shared the content when the console showed all the og tags correctly, but the crawler still went to login page (the unset html page)? This is the fb share code I'm using-  </p>
  
  <pre><code>&lt;div class="fb-share-button" data-href="http://www.example.com/pages.php?vip_poll='+app_id+'" data-layout="button_count" data-mobile-iframe="true"&gt;&lt;a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u='+url_enc+'&amp;amp;src=sdkpreparse"&gt;&lt;span id="fb_span"&gt;&lt;i class="fa fa-facebook-official" aria-hidden="true" style="color: white"&gt;&lt;/i&gt; Share &lt;/span&gt;&lt;/a&gt;&lt;/div&gt;
  </code></pre>