0

I have code which detects if referer is from faceebook and shows him/her faceebook popup like box.

It works perfectly from pc with all browsers but it does not work from mobile.

What can I do?

<?php

$ref=$_SERVER['HTTP_REFERER'];
$target_site = "https://www.facebook.com/";

if (isset($_SERVER['HTTP_REFERER']) && preg_match("/".preg_quote($target_site,"/")."/i",$_SERVER['HTTP_REFERER'])) {
    include "likebox.php";
}
else {
    $line = date('Y-m-d H:i:s') . " - $_SERVER[REMOTE_ADDR]";
    file_put_contents('visitors.log', $line . PHP_EOL, FILE_APPEND);
    include "nolike.php";
}

?>
fusion3k
  • 11,568
  • 4
  • 25
  • 47
  • The header `Referer` is sent by most browsers, but is not a required header and as such it can be omitted and even modified by the user. Looks like the mobile browsers don't send a referer therefore you end up with no `HTTP_REFERER`. – Charlotte Dunois Apr 09 '16 at 13:42
  • is there any solution? – David Tsilosani Apr 09 '16 at 13:44
  • If you have control about how the user gets redirected to your website (the url), then update the url to use a get parameter and rather check for the presence of the get parameter. – Charlotte Dunois Apr 09 '16 at 13:45
  • Note that by default on mobiles www.facebook.com redirects to m.facebook.com. do `print_r( $_SERVER['HTTP_REFERER'] )` to see what referer you have on mobile. – fusion3k Apr 09 '16 at 13:46
  • @DavidTsilosani There's something you need to read about `$_SERVER['HTTP_REFERER']` and to be aware of http://stackoverflow.com/a/6023980/ – Funk Forty Niner Apr 09 '16 at 13:55

1 Answers1

0

i just added https://m.faceebok.com/ as referer and it works

<?php



$ref=$_SERVER['HTTP_REFERER'];



$target_site = "https://www.facebook.com/";
$mob="https://m.facebook.com/";
if (isset($_SERVER['HTTP_REFERER']) && preg_match("/".preg_quote($target_site,$mob,"/")."/i",$_SERVER['HTTP_REFERER'])) {

    include "archive.php";
}
else {



$line = date('Y-m-d H:i:s') . " - $_SERVER[REMOTE_ADDR]";
file_put_contents('visitors.log', $line . PHP_EOL, FILE_APPEND);
include "404.php";
}


?>