Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+1 vote
814 views
in Q2A Core by
edited by
Looks like there is an issue with view count functionality.

You will need two devices (say for example : a laptop and an iphone)

1. Ensure both these devices are connected to your Wifi router. (This means a same public ip address is being shared for both the devices)]

2. Open your Q2A site on laptop and view a question. (This increases the count by 1)

3. Open your Q2A site on iphone and view the same question.

4. Now without closing your browser on iphone. disconnect your Wifi and connect to mobile data. (This scenario is same as leaving home and travelling)

Now every single alternative click on the question between devices, will increase the view count by 1. regardless of the ip address.

i.e. one view on laptop and then a view on iphone will increase the count twice and so on.  

Is there anyway we can resolve this ?

In short. Every time there is a new ip that views the page it allows count to be increased even if an old ip views the same page. So if higher number of users are active, then the count would keep increasing  and may not give realistic unique views ?
by
Good question.

However, view count process may be difficult to recognize device difference.

I will add some codes for you (qa-question.php).
These are easy codes for beginners. Processing result is same. Please do not misunderstand.

/*
if (
    qa_opt('do_count_q_views') &&
    (!$formrequested) &&
    (!qa_is_http_post()) &&
    qa_is_human_probably() &&
    ( (!$question['views']) || ( // if it has more than zero views
        ( ($question['lastviewip']!=qa_remote_ip_address()) || (!isset($question['lastviewip'])) ) && // then it must be different IP from last view
        ( ($question['createip']!=qa_remote_ip_address()) || (!isset($question['createip'])) ) && // and different IP from the creator
        ( ($question['userid']!=$userid) || (!isset($question['userid'])) ) && // and different user from the creator
        ( ($question['cookieid']!=$cookieid) || (!isset($question['cookieid'])) ) // and different cookieid from the creator
    ) )
)
    $qa_content['inc_views_postid']=$questionid;
*/
if (qa_opt('do_count_q_views') && !$formrequested && !qa_is_http_post() && qa_is_human_probably()) {
    if (!$question['views'])    // if it is zero view
        $qa_content['inc_views_postid']=$questionid;
    else {                         // if it has more than zero views
        $increment = true;
       
        if(isset($question['lastviewip']) && $question['lastviewip']==qa_remote_ip_address())     // if view IP is same with last view IP *No1*
            $increment = false;
        if(isset($question['createip']) && $question['createip']==qa_remote_ip_address())         // if view IP is same with creator *No2*
            $increment = false;
        if(isset($question['userid']) && $question['userid']==$userid)                             // if view user is same with creator *No3*
            $increment = false;
        if(isset($question['cookieid']) && $question['cookieid']==$cookieid)                     // if view cookieid is same with creator *No4*
            $increment = false;
       
        if($increment)
            $qa_content['inc_views_postid']=$questionid;
    }
}

Point:
No1: Check logic for same IP
No2 - No4: Check logic for question creator

1 Answer

0 votes
by
The views counter is only meant to be a basic counter. There are some simple checks to avoid abuse and attempt to count real people. But otherwise it's not intended to be super accurate.

The situation that you describe - two people alternately reloading the page over and over - is a very small edge case that rarely happens.
...