I have this code which i'm trying to use to count the number of hits a page has had before redirecting the user to another page.
The idea is that non-logged in users can only visit profile.php 6 times before being redirected to a signup page, but it is also doing this for logged in users and i want the logged in users to be able to access profile.php as many times as they want.
Can someone please show me where i am going wrong.
so an example is if session is null then limit page access to 6 times, but if session = logged in then allow unlimited access.
<?
!session_id() ? session_start() : null;
if(!isset($_SESSION['logged_in']) && empty($_SESSION['logged_in'])){
verify_profile_visit_limit();
}
function verify_profile_visit_limit(){
$free_profiles = array(99999,99998,99997,99996,99995,99994,99993);
if(in_array($_GET["id"], $free_profiles)) return;
if(! isset($_SESSION["page_access_count"])){
$_SESSION["page_access_count"] = 1;
}
$_SESSION["page_access_count"]++;
if($_SESSION["page_access_count"] > 6){
header("Location: limit.php");
exit();
}
}
?>