drruhc4944 2013-01-22 14:41
浏览 26

计算页面点击和重定向?

I have this code which i'm trying to use to count the number of hits a page has had before redirecting the user to another page.

The idea is that non-logged in users can only visit profile.php 6 times before being redirected to a signup page, but it is also doing this for logged in users and i want the logged in users to be able to access profile.php as many times as they want.

Can someone please show me where i am going wrong.

so an example is if session is null then limit page access to 6 times, but if session = logged in then allow unlimited access.

<?
!session_id() ? session_start() : null;

if(!isset($_SESSION['logged_in']) && empty($_SESSION['logged_in'])){
    verify_profile_visit_limit();
}

function verify_profile_visit_limit(){
    $free_profiles = array(99999,99998,99997,99996,99995,99994,99993);

    if(in_array($_GET["id"], $free_profiles)) return;

    if(! isset($_SESSION["page_access_count"])){
        $_SESSION["page_access_count"] = 1;
    }

    $_SESSION["page_access_count"]++;

    if($_SESSION["page_access_count"] > 6){
        header("Location: limit.php");
        exit();
    }
}

?>
  • 写回答

1条回答 默认 最新

  • dongxia19772008 2013-01-22 14:44
    关注

    The problem lies here:

    if(!isset($_SESSION['logged_in']) && empty($_SESSION['logged_in']))

    $_SESSION['logged_in'] can never be not set AND empty. You need to use the OR operator here.

    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用