Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $counter_name = "counter.txt";
- // Check if a text file exists. If not create one and initialize it to zero.
- if (!file_exists($counter_name)) {
- $f = fopen($counter_name, "w");
- fwrite($f,"0");
- fclose($f);
- }
- // Read the current value of our counter file
- $f = fopen($counter_name,"r");
- $counterVal = fread($f, filesize($counter_name));
- fclose($f);
- // Has visitor been counted in this session?
- // If not, increase counter value by one
- if(!isset($_SESSION['hasVisited'])){
- $_SESSION['hasVisited']="yes";
- $counterVal++;
- $f = fopen($counter_name, "w");
- fwrite($f, $counterVal);
- fclose($f);
- }
- echo "Liczba odwiedzin: $counterVal"; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement