简体   繁体   中英

Is it possible to specify Facebook OG meta tags in a php redirect page?

I have a php file which redirects users to another page and grabs the referring website.

    <?php
$ref = $_SERVER["HTTP_REFERER"];
$url = base64_encode($ref);
header( 'Location: http://link in here.com/?url=' . $url );
?>

The URL where this redirect page lives needs to be posted on Facebook, and so ideally needs OG meta tags to make it look nicer (image, title text etc)

I am no expert, but have played around a bit trying to put these tags below the php, in the php etc but with no joy. I'd imagine it needs to go in the php but before the header redirect?

Is this something that can be done? Any help would be much appreciated

Thanks

What if you were to try a header refresh.

header('Refresh: 0; url=http://link in here.com?url=' . $url);

Then you should be able to set the meta tags.

<?php
$ref = $_SERVER["HTTP_REFERER"];
$url = base64_encode($ref);
header('Refresh: 0; url=http://link in here.com?url=' . $url);
?>
<meta property="og:image" content="http://link in here.com/img.png"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM