Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cnt.php
- <?php
- ##############################################################################
- # Php Counter With Advanced Technology For The Prevention Of Reloading Pages #
- # Version: 1.4 - Date: 13.11.2014 - Created By Alessandro Marinuzzi [Alecos] #
- ##############################################################################
- function cnt($file) {
- session_start();
- global $pagecnt;
- $reloaded = isset($_SERVER['HTTP_CACHE_CONTROL']) && $_SERVER['HTTP_CACHE_CONTROL'] === 'max-age=0';
- $thispage = basename($_SERVER['SCRIPT_FILENAME']);
- if (!isset($_SESSION['thispage'])) {
- $_SESSION['thispage'] = $thispage;
- }
- if ($_SESSION['thispage'] != $thispage) {
- $_SESSION['thispage'] = $thispage;
- $new_page = TRUE;
- } else {
- $new_page = FALSE;
- }
- $pagecnt = rtrim(file_get_contents($file));
- if ((!$reloaded) && ($new_page == TRUE)) {
- $fd = fopen($file, 'w+');
- flock($fd, LOCK_EX);
- fwrite($fd, ++$pagecnt);
- flock($fd, LOCK_UN);
- fclose($fd);
- }
- }
- ?>
- showcnt.php
- <?php
- ##############################################################################
- # Show Counter Results - v.1.4 - 13.11.2014 By Alessandro Marinuzzi [Alecos] #
- ##############################################################################
- function gfxcnt($file) {
- global $number;
- $number = rtrim(file_get_contents($file));
- $lenght = strlen($number);
- $gfxcnt = "";
- for ($i = 0; $i < $lenght; $i++) {
- $gfxcnt .= $number[$i];
- }
- $gfxind = "<span class=\"counter\"><span class=\"number\">$gfxcnt</span></span>";
- echo $gfxind;
- }
- ?>
- #######################################
- ############## Under GPL ##############
- #######################################
- Usage:
- Put cnt.php and showcnt.php into a web root of your site inside a folder called "cnt". Then put at the top of your php web page (before calling other scripts) this piece of code:
- <?php session_start(); include("cnt/cnt.php"); cnt("log/mypage.txt"); include("cnt/showcnt.php"); ?>
- Then, where you like show the counter using this function in mypage.php:
- <?php gfxcnt("log/mypage.txt"); ?>
- Make sure you have in the root these folders: cnt, log. Otherwise you'll get an error... Have fun ;)
- Now you can stylize your php counter using css and the css class "counter" and "number" ;)
Advertisement
Add Comment
Please, Sign In to add comment