PHP/Javascript/HTML Hit Counter Primer Tutorial

PHP/Javascript/HTML Hit Counter Primer Tutorial

PHP/Javascript/HTML Hit Counter Primer Tutorial

Here is a tutorial that shows a way to create a very rudimentary PHP Hit Counter for a particular webpage. By “for a particular webpage” mean that to get a meaningful hit count for a website you probably are best placed to use a statistics package from your web provider or use a tool that the web provider gives you.

Link to some downloadable PHP programming code … rename to includeoncehc.php.

Link to some downloadable PHP programming code … rename to useofhc.php.

For this tutorial there is some flexibility in regards to what type of HTML element you use to display your Hit Count statistics. The code handles HTML elements with either/both Javascript DOM concepts of innerHTML and/or value. There is flexibility regarding your wording around the 0 (zero) of the HTML h1 element used in useofhc.php too, as long as 0 (zero), or other numbers for that matter, do not appear in your reworked prefixial wording.

You’ll see <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> in the code for useofhc.php within <head> and </head> which is code used to make websites user-friendly to mobile phones (and maybe have a look at some of the links of using this). Another approach to mobile phone friendly code is to express width values as percentage values, and you’ll see that principle being applied in useofhc.php also. You don’t have PHP? You could use a Javascript Cookie approach? (here? … or run tutorial, go View->Page Source with your web browser to get some starting ideas)

A PHP topic of interest that comes into play regarding this tutorial is the use of require_once() and/versus include_once() so take a look at require_once information and include_once information. You can actually do this job with one PHP where you plugin the contents of includeoncehc.php in place of the require_once() call, and you may want to try this. My apologies for the file naming confusion where includeoncehc.php is actually used with a require_once() call … but, c’est la vie.

You might be interested in blinking text, and this is achieved with this tutorial, by the use of <blink> and </blink>.

So enjoy this live run here.

Did you know?

You may notice that the word Javascript does not appear within the code of useofhc.php nor includeoncehc.php as above, so you may wonder how it can be claimed to involve Javascript. The reason is that Javascript is the default language of the <script> </script> notation, as used in this tutorial, where the PHP writes its own “Javascript” (by implication), and is the default language of HTML element event code as well, so, just as you can have
<a href=”//www.youtube.com/watch?v=h-mX9T2qyIQ#zkWMcRlE1mQ” onclick=”alert(‘FUNEX?’);'” title=”Two Ronnies Question”>FUNEX?</a>
you can just as well use syntax like
<a href=”//www.youtube.com/watch?v=h-mX9T2qyIQ#zkWMcRlE1mQ” onclick=”Javascript: alert(‘S,VFX’);'” title=”Two Ronnies Answer”>S,VFX</a>

If this was interesting you may be interested in this too.

This entry was posted in eLearning, Tutorials and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>