Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果页面被访问超过5次而忽略了某些页面,则将访问者重定向到其他url。_Php_Redirect_Count - Fatal编程技术网

Php 如果页面被访问超过5次而忽略了某些页面,则将访问者重定向到其他url。

Php 如果页面被访问超过5次而忽略了某些页面,则将访问者重定向到其他url。,php,redirect,count,Php,Redirect,Count,好的,我使用页面计数来计算用户访问profile.php的时间。如果未登录,则只能查看5个用户配置文件 每个概要文件都有profile.php的扩展名,例如profile.php?id=1或id=2等 页面计数工作正常,基本上,如果用户尝试单击5个以上的配置文件,它会将它们重定向到limit.php页面,该页面告诉用户他们已达到限制,并登录以查看更多内容 我已将其设置为排除以下几个配置文件 基本上,问题是,如果用户单击排除的配置文件(如99999或99998),则不会将用户重定向到limit.p

好的,我使用页面计数来计算用户访问profile.php的时间。如果未登录,则只能查看5个用户配置文件

每个概要文件都有profile.php的扩展名,例如profile.php?id=1或id=2等

页面计数工作正常,基本上,如果用户尝试单击5个以上的配置文件,它会将它们重定向到limit.php页面,该页面告诉用户他们已达到限制,并登录以查看更多内容

我已将其设置为排除以下几个配置文件

基本上,问题是,如果用户单击排除的配置文件(如99999或99998),则不会将用户重定向到limit.php页面。这是好的,因为我想它排除这些配置文件,但是,如果用户点击另一个配置文件,如1或8等之间,用户试图重新访问99999或99998,那么它不会让他们和重定向他们

有人能告诉我如何编辑脚本,即使在用户访问其他配置文件之后或期间,仍然允许用户访问配置文件99999或99998,而无需重定向它们吗

希望这是清楚的。谢谢

 <?php 

    !session_id() ? session_start() : null;
    if(!isset($_SESSION['page_access_count'])){
        $_SESSION['page_access_count'] = 1;
    }elseif($_SESSION['page_access_count'] >= 6){
        // redirect to signup page
        header('Location: limit.php');
        exit;
    }

      $free_profiles = array(99999,99998,99997,99996,99995,99994,99993); // array of profile IDs to exclude

    if (! in_array($_GET['id'], $free_profiles)) {
      $_SESSION['page_access_count']++;
    }


        ?>

我将限制验证逻辑包装在一个名为
验证\u配置文件\u访问\u限制的函数中。现在,我们可以使用
$\u get
(因为它是一个查询字符串)获取页面的“id”,如果它在
$free\u profile
数组中,则通过使用
return
函数退出
verify\u profile\u visit\u limit
函数跳过限制检查

!session_id() ? session_start() : null;

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"] = 0;
    }

    $_SESSION["page_access_count"]++;

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

我将限制验证逻辑包装在一个名为
verify\u profile\u visit\u limit
的函数中。现在,我们可以使用
$\u get
(因为它是一个查询字符串)获取页面的“id”,如果它在
$free\u profile
数组中,则通过使用
return
函数退出
verify\u profile\u visit\u limit
函数跳过限制检查

!session_id() ? session_start() : null;

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"] = 0;
    }

    $_SESSION["page_access_count"]++;

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

+1您可能还需要对您的答案进行解释。+1您可能还需要对您的答案进行解释。