简体   繁体   中英

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.

at the moment this script is placed in profile.php and it works fine, it limits the number of profiles a user can view. 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.

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(on profile foo){
   do bar
}
else {
   count++
}

Yeah. Use an if statement. Looks like you're familiar with them, and you've already got some decent understanding of PHP, so maybe I'm missing something?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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