douti0687 2014-05-24 07:46
浏览 14

如果没有引用并重定向流量类型,则重定向

I'm trying to load content from a different page if the user came to the page with NO referrer or if the user types my page in directly.

This is the code I would like to alter to be able to achieve this.

The code below redirects based on if the user has 1 of the IPs listed below, it will load the fakepage.php. I would like to alter this script so it can work if there is NO referrer, or if the user types in my url directly.

<?php
$banned = array('56.150.186.229','89.103.221.49');
$userIP = $_SERVER['SERVER_ADDR'];
if(in_array($userIP,$banned)) {
include_once('fakepage.php');
} else {
include_once('realpage.php');
}
?>

I'm trying to make this look as seamless as possible, so the user will not know they were redirected

  • 写回答

1条回答 默认 最新

  • dongmo1708 2014-05-24 08:00
    关注

    Use $_SERVER['REMOTE_ADDR'] to get the users ip (you may need another header if you are running behind a proxy or similar. Then check to see if $_SERVER['HTTP_REFERER'] is empty for your second condition.

     $banned = array('56.150.186.229','89.103.221.49');
     $userIP = $_SERVER['REMOTE_ADDR']; // likely users ip
     $noReferer = empty($_SERVER['HTTP_REFERER']);
     if(in_array($userIP,$banned) or $noReferer) {
       include_once('fakepage.php');
     } else {
       include_once('realpage.php');
     }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)