簡體   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