繁体   English   中英

在页数中排除个人资料ID?

[英]Exclude Profile ID in page count?

我使用页面计数来控制用户在被重定向之前可以查看页面的次数。 该页面为profile.php,如果用户单击用户个人资料,则将其带到扩展名为id = 1或id = 8等的profile.php。

目前,此脚本位于profile.php中,并且可以正常工作,它限制了用户可以查看的配置文件数量。 但我想排除一些配置文件。 这可能吗?

我是新手,还是php的初学者,所以如果有人可以告诉我,那真的会有所帮助。

谢谢,麻烦您了。

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

    // increase the page access session value
    $_SESSION['page_access_count']++;


    ?>

使用if语句。

if(on profile foo){
   do bar
}
else {
   count++
}

是的 使用if语句。 看起来您很熟悉它们,并且您已经对PHP有了一些体面的了解,所以也许我缺少了什么?

具体来说,为了便于维护,我会:

$free_profiles = array(1,8,12,14,96); // array of profile IDs to exclude

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM