I’m trying to redirect a user if they access a page more than 5 times.
So the basic idea is if a user is not logged in on my site and they are browsing a users profile (profile.php) then this counts the number of hits that cookie session has had and redirects to a page to say sign up or something.
I’m new to php and wouldn’t know where to start. Could someone please show me.
This is very easy to implement in PHP. Just set a session with the count value and read it after each access.Then you can redirect if the count is 5 or more. Below is a sample code
!session_id() ? session_start() : null; if(!isset($_SESSION['page_access_count'])){ $_SESSION['page_access_count'] = 1; }elseif($_SESSION['page_access_count'] >= 5){ // redirect to signup page header('Location:/signup.php'); exit; } // increase the page access session value $_SESSION['page_access_count']++; ...