Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
in Plugins by

After successfully install LDAP plugin from Zakkak, the view counts of my questions become all to be 1 (one). The IP of the viewers are all to be the LDAP server IP.

How can I get view couting work normally with LDAP login?

Q2A version: 1.7

1 Answer

+2 votes
edited by

I don't have the appropriate infrastructure to test this but I find this very related to issues in which load balancers are involved. Client executes a requests, goes through the LB and then an application node receives the request from the LB using that IP address.

This situations can be solved by configuring the LB (I think all of them do that by default) to set the X-Forwarded-XYZ HTTP headers. Then you process them in the application. Many frameworks do that by default.

I guess you could follow a similar approach where instead of using the LB you'd be using the LDAP (I don't know if you can modify or configure it to set those HTTP headers) and then, in your Q2A application, you'd have to modify the qa_remote_ip_address() function in qa-base.php (either by hacking the core or creating an override plugin) so that it takes the IP address from the previous HTTP header.

Plan B, would be to remove the IP check and increase those views with every refresh by removing these 2 lines in qa-include/pages/question.php:

( ($question['lastviewip']!=qa_remote_ip_address()) || (!isset($question['lastviewip'])) ) &&
( ($question['createip']!=qa_remote_ip_address()) || (!isset($question['createip'])) ) &&

I'll try the `X-Forwarded-XYZ HTTP headers` then
Triple check that. I have a clean install. I removed those 2 lines. Posted a question with a given user. Opened a private browsing session. Refreshed the page a couple of times and it got incremented (everything from the same IP, which was my localhost)
Great check. Thank you! Please also install LDAP plugin.
I can't. I mean, I've no LDAP server configured. Anyway, I hardly believe the plugin is changing something related to the view count you could remove the whole IF statement near those lines and only leave the line with the:
That will always increase view counts without considering any condition. If that actually works, then you can see exactly which condition is failing there. EG: Maybe the user agent you're using is not in the list for the qa_is_human_probably() to consider it as a human.