I am racking my brain as to why this isn't working.
What I would like to achieve, is to restrict access to a page on my own Website, only if coming from a certain website, Facebook for instance.
Since a link will be posted on 1 or more Facebook pages and/or my personal profile, would like the script to execute if coming from Facebook and/or any other "PAGES" it's posted on.
For instance, if I post my link on www.facebook.com/This_is_my_PAGE or is posted on my personal profile www.facebook.com/freds_personal_profile or someone shares my link on Facebook, would like the page accessible only to those coming from the Facebook domain.
I found the script below while searching for a solution, but it's echoing my error message, instead of redirecting to the link in question.
$target_site = 'https://www.facebook.com/';
if (isset($_SERVER['HTTP_REFERER']) && preg_match("/$target_site/",$_SERVER['HTTP_REFERER'])) {
// do something with people from facebook.com
}
else {
// do something else with everyone else
echo "Sorry, viewable to Facebook fans only.";
}