0

Hi I'm trying to change the picture for facebook thumbnail by having php set the image in the meta tag depending on the page. I have this code but for some reason when I go to Facebook and debug it it actually shows the variable and not what the value of the variable is. Here is my code please help thank you!

<?php
if($ifpage == 'picture.php')
{
$metaimage = '<meta property="og:image" content="http://www.quickdailylaugh.com/photos/print $picture" />';
print($metaimage);
}
?>

3 Answers3

1

Your variable is inside of a string enclosed with single quotes. Single quotes will take the literal value of the string $varname and not translate the variable to it's value. You need to use double quotes. Example:

$var1 = 'test';
$foo = 'The value of var1 is: $var1'; // The value of var1 is: $var1
$bar = "The value of var1 is: $var1"; // The value of var1 is: test
Jonathan Kuhn
  • 15,279
  • 3
  • 32
  • 43
  • 1
    The OP's code is full of undefined variables, so even if this is fixed, I doubt it will work. – Amal Murali Apr 16 '14 at 17:52
  • @AmalMurali I would say it is more likely that this isn't the full code and the variables are defined elsewhere. Or maybe they are defined in the query string and register globals = On. Or maybe they are defined in an auto_prepend file. Point is, it is still possible this is the complete code and no errors would be thrown. – Jonathan Kuhn Apr 16 '14 at 17:54
1

To interpret the varible you must use double quotes.

<?php
if($ifpage == 'picture.php')
{
$metaimage = "<meta property=\"og:image\" content=\"http://www.quickdailylaugh.com/photos/print $picture\" />";
print($metaimage);
}
?>
vgrdominik
  • 91
  • 4
0

I had to do another query for it to show... Thank you all for the answers here is what i used...

<?php
if($ifpage == 'picture.php')
{
$photoid = $_GET['picture'];
$sql = "SELECT * FROM photos WHERE id=$photoid";
$pic = mysql_query($sql);
while($row = mysql_fetch_array($pic))
        {
$picture=$row['picture'];
}
$metaimage = "<meta property=\"og:image\" content=\"http://www.quickdailylaugh.com/photos/$picture\" />";
        print($metaimage);
}else{
?>