0

First I am new to PHP, this is my first script for the purpose of providing og tags dynamically.

Facebook OG debug page seems to somehow acquire the actual php script which I thought it was impossible. My current understanding of server-side scripts is that the server should only execute them and not reveal them?
It appear Facebook is grabbing the initialization code of my php rather than the final execution of it. Unless my understanding of php variable scoping is skewed?? I am totally puzzled.

Here is my php logic. I initialize my php variables $ogTitle and $ogImage to some default strings, then proceed to update the same variable based on what my php scrapes from the xml/media specified on the url.

Here is my PHP

<?php
// Set the defaults...
$ogTitle=".Universal Media Thru Internet." ;
// the following inserted for debug to prove facebook is grabbing this value ??? instead of the final derived one.
$ogTitle="الباء WRONG TITLE MEANT TO BE THE DEFAULT IF PHP DOES NOT DYNAMICALLY DERIVE ONE" ;
$ogDescription="Mumti the Next Generation" ;
$ogUrl = "http://mumti.org" ;
// 20180413
if ($_GET['ms'] != '') {
    $url = $_GET['ms'];
}
if ($_GET['mq'] != '') {
    $url = $_GET['mq'];
}
if ($url != '') {
    $xml=simplexml_load_file($url) or die("Error: Cannot access XML $url");

//
    $Pic = $xml->SLIDE[0]->PIC;
    $rcbmp_root = $xml->rcbmp_root;
// -) derive final path for image
    if ($rcbmp_root == "")
        $ogImage = dirname($url) . "/" . $Pic ;
    else
        $ogImage = dirname($url) . "/" . $rcbmp_root . $Pic ;
//
    $ogTitle = $xml->SLIDE[0]->TXT;


    // Cleanup the ogImage URL (aka path normalization)
    $u = parse_url(strtolower($ogImage)); // returns the URL components in associative-array
    $u['path'] = simplify($u['path']); // removes the .. notations from the path component
    $ogImage = "{$u['scheme']}://{$u['host']}{$u['path']}"; // piece the components together into a URL
}

?>

The simplest of visual validator is the following link (please paste AS-IS in the address bar of Chrome or Firefox browsers with the prefix view-source: )

view-source:http://mumti.org/?mq=http://arabicrescue.com/AR/KIDS/WORDS/WORD/02/DARC01.XML

It reveals the correct og:title and valid og:image as the following:

<meta lang="ar" property="og:title" content="البَاءُ" />
<meta property="og:image" content="http://arabicrescue.com/ar/arabic/letters.bmp/400_1/02.png">

However, using the exact same URL, Facebook debug page insist there is something wrong

https://developers.facebook.com/tools/debug/sharing/?q=http%3A%2F%2Fmumti.org%2Findex.html%3Fmq%3Dhttp%3A%2F%2Farabicrescue.com%2FAR%2FKIDS%2FWORDS%2FWORD%2F02%2FDARC01.XML

Facebook appears to be grabbing the initialization values of my php script and nothing from the "if ($url != '') { ..." evaluation.

Thanks for shedding any light on this, because I failed to explain myself to facebook bug reporting. :( https://developers.facebook.com/bugs/134977464017792/

Meryan
  • 1,285
  • 12
  • 25

1 Answers1

0

The fix for Facebook was to provide og:url as the actual url and not just the root url to the website. Otherwise, it shows og:title as null (ie. "") and og:image and some older image (my site logo) it's crawler robot scraped some time ago. Something I could not really understand and explain.

Anyways with the following additional php code, facebook is returning the title and image correctly.

enter image description here

$ogImage = str_replace( " ", "%20", $ogImage );
// -) provide canonical url
// https://stackoverflow.com/questions/6768793/get-the-full-url-in-php
$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
$ogUrl = str_replace( " ", "%20", strtolower($actual_link) );
Meryan
  • 1,285
  • 12
  • 25