简体   繁体   English

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

[英]Exclude Profile ID in page count?

I'm using a page count to control the number of times a user can view a page before being redirected. 我使用页面计数来控制用户在被重定向之前可以查看页面的次数。 the page is profile.php and if a user clicks on a users profile this takes them to profile.php with the extension id=1 or id=8 etc. 该页面为profile.php,如果用户单击用户个人资料,则将其带到扩展名为id = 1或id = 8等的profile.php。

at the moment this script is placed in profile.php and it works fine, it limits the number of profiles a user can view. 目前,此脚本位于profile.php中,并且可以正常工作,它限制了用户可以查看的配置文件数量。 but i want to exclude a few profiles. 但我想排除一些配置文件。 is this possible? 这可能吗?

I'm new and a beginner to php so if someone could please show me that would really help. 我是新手,还是php的初学者,所以如果有人可以告诉我,那真的会有所帮助。

Please and thank you. 谢谢,麻烦您了。

<?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']++;


    ?>

Use an if statement. 使用if语句。

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

Yeah. 是的 Use an if statement. 使用if语句。 Looks like you're familiar with them, and you've already got some decent understanding of PHP, so maybe I'm missing something? 看起来您很熟悉它们,并且您已经对PHP有了一些体面的了解,所以也许我缺少了什么?

Specifically, for ease of maintenance, I'd do: 具体来说,为了便于维护,我会:

$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