How to calculate page views in Codeigniter and limit the number by IP address?

I want to calculate how many times people viewed my user profiles on my site.

I would like to keep the score in my database and stop counting when the user refreshes the page. IP restriction.

I understand that the cache of ip addresses will need to be created and cleared daily.

Is there any instruction on how to do this. Can anyone tell me about this?

+3
source share
3 answers
  • You can use $this->input->ip_address()to accept the IP address of the user in the controller
  • In the database you save ip, the time when the user first visited the site and the counter.
  • 24 , .
  • 24 , ip .
  • : $this->db->select_sum("counter")->get("views_table"); .
+13

databasetable:

id | page_id | ip_address | views

ip- ($_SERVER['REMOTE_ADDR']), , ip- , views, views . views > $x .

, ?;)

" , "; , , (- F5)? , ...

cronjob, , poormans cron (google )

0
  • , , , .
  • .
  • , giorgio, IP-, DATETIME.
  • , , , IP- : ; , IP-, .
  • Set up cron cleaning work once a day, determining the duration of tracking: delete all records older than 1 day, 2 days, weeks — all you want is how long the IP address will be tracked. This means that when the same IP address is visited after x days, the browsing counter is likely to increase if it is not already in the database.
0
source

All Articles