top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

PHP: Is there a way to run a Function only once when a logged in user accesses a page multiple times?

+1 vote
389 views
PHP: Is there a way to run a Function only once when a logged in user accesses a page multiple times?
posted Mar 25, 2016 by Ritika Sharma

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote
 
Best answer

create a session variable for eg count which is created when user logged in for the first time and initialize it with zero..
so when users accesses a page ,increment the count value in the script where we check whether the user session is valid or not...
so for the second time count value increments to one..within the same script use if($count==0) call the function...so it will run for the first time...when logging out..invalidate this count session variable also...

answer Mar 28, 2016 by Aman Mehrotra
Similar Questions
0 votes

I have a question about using a php user class and session variables. Let's say that I have managed to create a user class that finds a particular person from the database query.

As I move about the site from page to page it would be nice to be able to use the current user inside the user class without needing to re – look them up in the database multiple times

Q: so is there a way to combine the current active user in the class with session variables so that they can be used multiple times? If so, how would this work?

0 votes

For example say I want include("abc.php") two times in a PHP page?

0 votes

Used the sizeof of function, which gives 1; why?
I want to know the size of the entire function. How to achive it?

#include <stdio.h>
void (*p)(int); 
void test_func(int data)
{
  printf("%d\n",data);
}

main(void)
{
    p = test_func;
    (*p)(4);
    printf("%d",sizeof(test_func));
}
...