This is a really quick & easy piece of PHP code to count the page views. It’s not fantastic (It lacks any real tracking abilities), but for some things it does the trick.
The Theory
Every time someone views a page, PHP will increase a number stored in a file by 1. If we want to see how many people have view that page, we just check the file.
The Code
<?php # File created on 11th February 2009 by Mike Rogers (http://www.fullondesign.co.uk/).
## Start defining constants ##
define(RUN_ERRORS, TRUE); // Do you want the script to display errors? TRUE = yes you do.
define(LOG_URL, '/home/user/logs/'); // Put the location of where you want to put the logs. Make sure this is absolute
$filename = rawurlencode(base64_encode($_SERVER['PHP_SELF'])); // Takes the filename then makes it network safe.
## End defining constants ##
## Parse filename ##
$filename = LOG_URL.$filename.'.log.txt';
##
// Check that the file exists, encase of the logs being removed or being invalid.
if(is_writable($filename) && is_readable($filename)){
// We should be able to read and write it
$file_contents = file_get_contents($filename);
// Check its a number, the logs could have been hacked at some point.
if(is_numeric($file_contents)){
$file_contents = $file_contents + 1; // Adds 1 to the current number in the log. $file_contents++; would also work.
file_put_contents($filename, $file_contents);
}else{
if(RUN_ERRORS === TRUE){
echo 'File ('.$filename.') contents is not numeric';
}
}
} else {
// We should create the file if we can.
if(is_dir(LOG_URL) && is_writable(LOG_URL) && !file_exists($filename)){ // Checks that the LOG_URL is a wriable directory, and the file does not already exist.
// lets create the file.
file_put_contents($filename, '1');
}else{
if(RUN_ERRORS === TRUE){
echo 'Cannot/write find directory/file ('.$filename.')';
}
}
}
/* Here is how to show how many people have view the file */
echo ('This file has been view by '.file_get_contents($filename).' people');
/*
You are free to share, modify and use this code for commerical uses. Please give a link back (to http://www.fullondesign.co.uk/ ) if you can, but you don't have you.
I claim no liability for this code, you use it at your own risk.
*/
?>
WordPress is fantastic, one of its main strengths is it’s expandability. WordPress has thousands of plugins, however most of these plugins are a big waste of disc space. Here are some actually useful plugins for wordpress.
WP Super Cache
One of the most essentially plugins you will ever need on wordpress, this plugin decreases load per page (by caching the content) which improves your websites performance and can lower server costs. This plugin is especially nessessary if your blog is running on a low quality server or you receive high volumes of traffic.
TinyMCE Advanced
TinyMCE is the editor used in wordpress, however in wordpress it has been set up lacking quite a few features. This plugin lets you add more features to the editior.
Akismet
Spam comments are a real pain in wordpress, however this plugin sifts through your comments looking for spam. This can keep your blog on tip-top condition which should improve your rankings.
Google XML Sitemaps
XML sitemaps are very important when it comes to SEO, however creating them and keeping them up-to-date is a hassle. This plugin keeps your sitemap up-to-date.
Sociable
Everyone like sharing (especially when it generates you more traffic), this plugin adds links to digg, delicious and other social sharing websites at the bottom of your posts (see below).
StatPress
Any good webmaster will tell you that ‘Knowing your visitors is useful’, this plugin analyses where your clients comes from and also generates pretty graphs.
WordPress Automatic Upgrade
This is one of these plugins which is more of a time saver, then a essential. But if your anything like me (too lazy to spend 2 minutes updating some files) this plugin will be a life saver.
A cron is a program which allows users to execute scripts at a specified time and date. In the web development world they are normally used to update caches or run complex pieces of code (this in theory should improve the user experience).
In this short video I will explain the basics of crons & how to run a PHP at a regular interval.
PHP Cron Commands
Usage: php [-q] [-h] [-s] [-v] [-i] [-f <file>]
php <file> [args...]
-a Run interactively
-C Do not chdir to the script’s directory
-c <path>|<file> Look for php.ini file in this directory
-n No php.ini file will be used
-d foo[=bar] Define INI entry foo with value ‘bar’
-e Generate extended information for debugger/profiler
-f <file> Parse <file>. Implies `-q’
-h This help
-i PHP information
-l Syntax check only (lint)
-m Show compiled in modules
-q Quiet-mode. Suppress HTTP Header output.
-s Display colour syntax highlighted source.
-v Version number
-w Display source with stripped comments and whitespace.
-z <file> Load Zend extension <file>.
Related Links
If you are interested in learning more about crons, please check out the following sources:
Internet Explorer 8 RC1 has just been released. You can download it here.
Downloading/Installing
At a miniature 16.2mb IE8 RC1 took me 30 seconds to download and it took in 9 minutes + 1 restart to get to my first web page.
It also imported my FireFox feeds and bookmarks, which was useful.
Extensions
I couldn’t check what add-ons where available as the IE add-ons website was down (see screenshot). However, IE did open a nice tab showing some “accelerators” I could use (I think they are like google gears, but MS style).
Speed
Overall, IE8 seems faster than IE7 however compared to Opera, Firefox and Safari it’s just does not feel as snappy. However in most speed test done by professionals it’s a marginal difference, if you enjoy statistics take a look here.
Backward Compatibility
A really neat feature of IE8 is a built in “compatibility button”, which essentially means if a website is not working correctly in IE8 you can run it as if it was IE7.
Rendering
I love how it renders my pages, IE8 seems to render exactly the same as FF3.
There still seems to be some different padding/margin differences, but maybe something to look forward to in IE9?
Overall
I’m a firefox fanboy at ther end of the day, so i will not be moving to IE8. However, I will have it installed and I may use it from time to time