Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function set_count($file = 'counter.txt'){
- if(file_exists($file)){
- //read the value of the file
- $handle= fopen($file, 'r');
- //increase it by one
- $count = (int) fread($handle, 20) + 1;
- //write the value in file
- $handle= fopen($file, 'w');
- fwrite($handle, $count);
- fclose($handle);
- }
- else{
- //creat it
- $handle = fopen($file, 'w+');
- //set the defualt value 1
- fwrite($handle, 1);
- fclose($handle);
- $count= 1;
- }
- return $count;
- }
- echo set_count();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement