Online computer courses, code, programming tutorial and sidebar information for monitoring Canadian S&P/TSX index. Build friendship and networking. Welcome to visit my blogs often!!! I also have two other sites: YouTube Channel and Google site.
Adsense
Popular Posts
- PHPWind-- A PHP forum script applcaition in China
- Free host forum is not reliable
- Formatting my post
- Powerful js library datable to export table in pdf, excel, sorting, freezing column and table header fixed (sticky)
- job interview questions (1)
- Set up a child account and set screen time limit in Windows 8
- WinMerge - file and folder differencing and merging tool for Windows
- PHP: add a download as pdf file button in report page
- phpexcel toggle expand and hide column in EXCEL and summary
- PHP connect IBM db2 database in XAMPP
Tuesday, December 18, 2012
A Simple PHP Visitor Counter
Design a simple PHP counter without using MySQL database, only using an external file 'visitorcounter.txt'. PHP functions used here: file_exists, fopen, fwrite,fgetc,fclose.
visitorcounter.php
<?php
//A simple PHP counter
//Using external file visitorcounter.txt
//to store counter instead using MySQl database
function visitorcounter()
{
$file='visitorcounter.txt';
if(!file_exists($file)){
$counter = 0;
$cf=fopen($file,"w");
fwrite($cf,$counter);
fclose($cf);
}else{
$cf=fopen($file,"rw");
$counter=fgetc($cf);
fclose($cf);}
$counter++;
$cf=fopen($file,"w");
fwrite($cf,$counter);
fclose($cf);
return $counter;
}
?>
index.php, call visitorcounter.php
<?php
require("visitorcounter.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Visitor Counter</title>
<meta name="author" content="Jiansen" />
<!-- Date: 2012-12-18 -->
</head>
<body>
<h1>Welcome to visit My Homepage</h1>
<br /> <hr />
<font size=7 color=red>
You are visitor <?php echo visitorcounter(); ?>.
</font>
</body>
</html>
Video for this demo:
Subscribe to:
Post Comments (Atom)
How to remove stop words in Python
ReplyDeleteHow to find the stop words in nltk Python
Python language detection and translation program
TextBlob Sentiment Analysis Python Example
Python Spell Checker Program
Python remove punctuation from string