相同的if else代码不适用于移动设备

时间:2016-04-09 13:39:56

标签: php mobile refer

我的代码可以检测referer是否来自faceebook并显示他/她的faceebook popup like box。

它适用于所有浏览器的PC,但它无法在移动设备上运行。

我该怎么办?

<?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";
}

?>

1 个答案:

答案 0 :(得分:0)

我刚刚添加了https://m.faceebok.com/作为引用并且它可以正常工作

<?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";
}


?>