• Log in or sign up for an account here: https://www.sythe.org/login

Hit counter site

You use a PHP-generated image in relation to a database that tracks the number of requests for the image from your server.

It's pretty simple, but you'd also have to add the hitcounter generation pages if you want to make it an online service like the site you linked to.
 
You use a PHP-generated image in relation to a database that tracks the number of requests for the image from your server.
For just one simple counter I'd recommend using flat-file storage.
 
anyone have a simple html hit counter code?
 
Member of the Month Winner
Sythe's 10th Anniversary
anyone have a simple html hit counter code?
You can't use HTML for such a thing. HTML is just a markup-language used by the browser to display a static webpage.
 
You can't use HTML.

If you are new at web programming I suggest making a flat file counter with PHP.
 
Firefox crashed the first time I wrote this so I had to re-do it. :'(


This short guide will allow you to add a counter to your pages. In order for this counter to work, you will need:

- A professionally hosted website
- MySQL

If you lack either of those things (meaning you have a free hosted website, or something besides MySQL) then do not continue on with this guide, as it will be no help to you.

Beyond that, you will be able to create your counter. The rest of this guide is useful for you only if you have:

- CPanel
- MySQL Administration in CPanel
- PHPMyAdmin

If you lack any of those things, contact me so I can write you a script which will take the place of this guide. If you don't know if you have these things, follow steps 1 and 4 to find out. If you cannot find any of the things in step 1 and 4, you do not meet the requirements.


If you've met all the requirements so far, follow these steps to create your counter.





Step 1: Locating your MySQL administration

1. Open up CPanel.
2. Locate the MySQL administration icon, which should look something like this:

screenshot_1.png


3. Click that icon.



Step 2: Creating your database

1. Locate this box:

screenshot_5.png


2. Type into the box "hits" and hit the "Create Database" button.

3. When you create your database, a prefix may be added. To makes sure you know the real name of your database, look for it in the list here:

screenshot_7.png


4. Write down the name of your database.



Step 3: Creating a user and adding it to the database

1. Locate this box:

screenshot_6.png


2. Type in a username and password to use.

3. Hit the "Create User" button.

4. Locate the "Current Users" right above the boxes you typed the username and password into. Check the username, because a prefix may have been added.

4. Write the username and password down.

5. Locate the "Add users to your databases" section and configure it like this:

screenshot_8.png


6. Hit the "Add User to Database" button.



Step 4: Locating PHPMyAdmin

1. Find something that looks like this:

screenshot_2.png


2. Click that link.



Step 5: Adding a Table

1. Find your database on the left side and click it. It should look something like this:

screenshot_9.png


2. Find this and type in "hits" for the name and "2" for number of fields:

screenshot_10.png


3. Configure it like this:

screenshot_11-1.png


Bookmark 1

4. Now go click this:

screenshot_12.jpg


5. Set it up like this and click the "Go" button in the right below the two fields you filled out, and make sure you have the "ignore" box checked like shown in the picture:

screenshot_13.png


END BOOKMARK



Step 6: Adding the Counter

1. Make your page a .php file instead of a .html or .html if you havn't done so already. (For some people this may require you to either re-upload the file as a .php or just to rename the file.)

2. Add the following code anywhere inside the <body> tag where you want your counter number to appear replacing all instances of USERNAME, PASSWORD, DATABASE, and "home", if you plan on adding this to a different page besides the home page. :

PHP:
<?php
$connection = mysql_connect("localhost","USERNAME","PASSWORD");

mysql_select_db("DATABASE",$connection);

$result = mysql_query("SELECT * FROM hits WHERE page='home'") or
die(mysql_error());

$row = mysql_fetch_array($result);

$temp = $row["number"]+1;

mysql_query("UPDATE `DATABASE`.`hits` SET `number` = '$temp' WHERE CONVERT( `hits`.`page` USING utf8 ) = 'home' LIMIT 1");

echo $temp;
?>

NOTE: If you'd like to add this to multiple pages, repeat Bookmark 1 and Step 6.



THAT'S IT, now you've got a working page view counter!
I hope this guide helped, it took me a quite a while to complete. (:
 
Runescape Gamblingrunescape gambling
Back
Top