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
- How to blend adsense inside your post?
- Formatting my post
- Notepad++ - Add C++ compiler
- Install PHPMailer 5.2.4 and use smtp gmail
- Set up a child account and set screen time limit in Windows 8
- Wayback Machine - see archived versions of web pages across time
- phpexcel toggle expand and hide column in EXCEL and summary
- Install PHP ibm_db2 extension in Linux (redHat)
- PHP: add a download as pdf file button in report page
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