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
- Using Cron Job to process PHP scripts
- job interview questions (1)
- PHP connect IBM db2 database in XAMPP
- Free host forum is not reliable
- Powerful js library datable to export table in pdf, excel, sorting, freezing column and table header fixed (sticky)
- Install PHPMailer 5.2.4 and use smtp gmail
- Sweet Alert JS library - beautiful replacement of JavaScript Alert
- Notepad++ - Add C++ compiler
- Set up a child account and set screen time limit in Windows 8
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