Determine how many times a webpage has been accessed.

I was wondering if there was a way to determine how many times a particular web page was accessed on the server. If possible, I would like to do this via cPanel, since the website was created in Wordpress, but I made the page in question from scratch and simply loaded it into another directory. So, I can’t rely on plugins (right?), And I don’t know enough PHP or JavaScript to communicate with the web server and store this information on it ...

-1
source share
2 answers

Your server already does this, it is called a log file . If you select it for this page and count the number of logs, then you will have the number of whistors who viewed this page. This, however, is inefficient and does not work with CPanel.

You can then write a simple script to insert a record into the database every time someone visits this page. Then your answer can be requested using the custom PHP you add to CPanel. It is more efficient, but will reinvent the wheel.

But the real answer is to get analytic software. There are a number of products that can do this for you:

  • Google Analytics. Google, , . Google - , , Google Analytics, .

  • Piwik. , . , , Google Analytics. , , , CPanel. , Google Analytics, .

+1

include PHP, PHP .

- .

file_put_contents, , FTP. ( cpanel)

<?php
session_start();
if(!isset($_SESSION['mySiteWasAccessed'])) {
    $_SESSION['mySiteWasAccessed'] = true;
    file_put_contents("my_log_file.txt", "My page was accessed", FILE_APPEND | LOCK_EX);
}
?>

.TXT , script.

.PHP, , .

. , , :

http://php.net/manual/en/function.file-put-contents.php

http://php.net/manual/en/function.include.php

, :

http://php.net/manual/en/function.mail.php

+1

Source: https://habr.com/ru/post/1679226/


All Articles