I was wondering if there is a way to determine how many times a specific webpage has been accessed on the server. If possible, I would like to do this via cPanel, since the website is made in Wordpress, but the page in question I made from scratch and just uploaded it in another directory. So, I can't rely on plugins (right?) and I don't know enough PHP or JavaScript to communicate with web server and store that info on it...
Determine how many times webpage has been accessed
3.9k views Asked by dzenesiz AtThere are 2 answers
Emil S. Jørgensen
On
If you use the include function in PHP you can make a statistics PHP file and include it on all your pages.
The easiest way would be to simply create a log file.
Using file_put_contents you can easily append data to a log file, that you can then either download or access through your FTP of choice. (Like 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);
}
?>
The code above will write a new line to a .TXT file the first time a unique user accesses the script.
Now you just need to include a .PHP file containing this information on each page of your site.
See the following links for documentation, pointers, examples and general help:
http://php.net/manual/en/function.file-put-contents.php
http://php.net/manual/en/function.include.php
If you want to get advanced you can look at the mail function for a notification method:
Related Questions in JAVASCRIPT
- Using Puppeteer to scrape a public API only when the data changes
- inline SVG text (js)
- An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
- Storing the preferred font-size in localStorage
- Simple movie API request not showing up in the console log
- Authenticate Flask rest API
- Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
- How to request administrator rights?
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- In Datatables, start value resets to 0, when column sorting
- How do I link two models in mongoose?
- parameter values only being sent to certain columns in google sheet?
- Run main several times of wasm in browser
- Variable inside a Variable, not updating
Related Questions in PHP
- How to add the dynamic new rows from my registration form in my database?
- Issue in payment form gateway
- How to create a facet for WP gridbuilder that displays both parent and child custom fields?
- Function in anonymous Laravel Blade component
- How to change woocomerce or full wordpress currency with value from USD to AUD
- General questions about creating a custom theme Moodle CMS
- How to add logging to an abstract class in php
- error 500 on IIS FastCGI but no clue despite multiple error loggings activated
- Composer installation fails and reverts ./composer.json and ./composer.lock to original content
- How to isolate PHP apps from each other on a local machine(Windows or Linux)?
- Laravel: Using belongsToMany relationship with MongoDB
- window.location.href redirects but is causing problems on the webpage
- Key provided is shorter than 256 bits, only 64 bits provided
- Laravel's whereBetween method not working with two timestamps
- Implementing UUID as primary key in Laravel intermediate table
Related Questions in CPANEL
- Cpanel filter encoding utf-8?
- How to setup SES SMTP in WHM cPanel shared hosting
- Nextjs App works with Host File IP, return 400 Bad Request with Domain
- i have my cpanel login of my website. how can i change hosting through cpanel?
- NodeJS running on cpanel
- How to kill number of processes in cpanel
- Publishing an SSR app w/ Angular 17 on a cPanel is possible, right?
- After pointing Cpanel domain to Shopify, I am not able to either Receive or Send Emails
- NodeJS server and client on Cpanel Not Working
- Image is not displayed/loaded in my django website which i deployed on Cpanel
- Cpanel Deployment getting Cannot GET / error React Next js
- React/nodejs Cpanel project - frontend won't connect to backend
- Move BitBucket repository to cPanel
- Is it possible to reject non secured (non ssl / wss) websockets with socket.io?
- External Email html blocked in script php if HTML
Related Questions in HTML
- How to store a date/time in sqlite (or something similar to a date)
- How to use custom font during html to pdf conversion?
- Storing the preferred font-size in localStorage
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- Is there any way to glow this bulb image like a real light bulb
- With non-graphical maps in Leaflet, zoomDelta doesn't work
- What can I do to improve my coding on both html and css
- Uncaught TypeError: google.maps.LatLng is not a constructor at init (script.js:7:13)
- Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
- Displaying a Movie List on a Website Using Jinja2 and Bootstrap
- How to redirect to thank you page after submitting a Google form embedded into a Google Site?
- Storing selected language in localStorage
- Fences (parenthesis, braces) in HTML and MathML
- Understanding Scroll Anchoring Behavoir
Related Questions in VISITOR-STATISTIC
- How to count thousands of daily visits
- How to make visits count seperate for each item
- Count visits of WordPress site
- Suggested table scheme for saving visitors by week days and hours statistics
- Can Google Analytics track the profile of website visitors?
- How to count number of real visitors on a specific page using PHP
- Calculating significance for multiple variations in AB testing in python
- Creating sparse matrix and then running predictive analysis on the data
- How is it possible to have a repository with cloners and no visitors?
- Visitor Counts in PHP stopped working suddenly
- How do I show visitor count in my page using google analytics?
- Separate Visitor Counter for 2 different pages in same Laravel Project
- Need the Keywords Search details form a Particular country
- Compare two web pages (A/B testing) - Two sample portion test
- Can I View Search Engine Referred Pages In AWStats?
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Your server is already doing that, it is called the log file. If you grep it for the given page and count the number of log enteries, you will have the number of vistors who viewed that page. This, however, is inefficient and doesn't "work with CPanel".
Next, you could write a simple script to insert an entry to a database every time someone visits that page. Then your answer could be queried by custom PHP you add to CPanel. This is more effiecient, but would be reinventing the wheel.
But, the real answer is get analytics software. There are a number of products that can do this for you:
Google Analytics - This is a Google Product that collects lots of different types of user information, generates powerful reports, and is freely available online. It has the downside of giving that data to google - so if you have a privacy policy, you'd want to specifically call out the Google Analytics tracking you're doing.
Piwik - This you can either get cloud-hosted, or host it yourself. It's free open-source software that does most of what Google Analytics does. You'd own your data and that data would reside on your server, there are widgets that could be embedded on pages so with some work could be integrated into CPanel. The reports are not as polished looking as Google Analytics, but that might be worth the trade-off.