简体   繁体   English

计算网页点击数并重定向?

[英]count page hits and redirect?

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. 这个想法是,未登录的用户在重定向到注册页面之前只能访问profile.php 6次,但是它也对登录的用户这样做,我希望已登录的用户能够访问profile.php他们想要多少次。

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为null,则将页面访问限制为6次,但如果session =登录,则允许无限访问。

<?
!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();
    }
}

?>

The problem lies here: 问题出在这里:

if(!isset($_SESSION['logged_in']) && empty($_SESSION['logged_in']))

$_SESSION['logged_in'] can never be not set AND empty . $_SESSION['logged_in']不能设置为 You need to use the OR operator here. 您需要在此处使用OR运算符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM