Run PHP Function once

后端 未结 3 1161
天涯浪人
天涯浪人 2021-01-23 02:12

Is there a way to run a PHP FUNCTION \"fun();\" only once when a logged in user accesses a page multiple times?

here is the function.



        
相关标签:
3条回答
  • 2021-01-23 02:51

    Using authentication/sessions and storing the number of times a user has accessed that page in say a database for example or a flat file. You'll need to persist their access count to that page regardless.

    0 讨论(0)
  • 2021-01-23 02:53

    Can you not run the function, then store a $_SESSION variable? For example:

    if (!isset($_SESSION['function_ran']) || $_SESSION['function_ran'] != '1') {
        fun(); // run function
        $_SESSION['function_ran'] = '1';
    }
    
    0 讨论(0)
  • 2021-01-23 03:04
    if(!isset($_SESSION['visitedOnce'])){
        fun();
        $_SESSION['visitedOnce'] = true;
    }
    
    0 讨论(0)
提交回复
热议问题