printer friendly version

Installing click counter script

This is a tutorial on installing a simple click counter script you can download here. You will surely find this script very easy to install.

Introduction

Have you wondered how file previews and downloads, or hits given to affiliate links are counted? This is a little script I wrote for my own needs, but now it's avilable for download :)

Requirements: Knowledge of HTML and FTP, FTP client, host that supports PHP execution.
No SQL databases needed.

Offcourse, to be sure that this is the script you need, you can see its demonstration right here. Click on the link below, and then refresh this page. You will see that the number has increased by one :)

In obscuro hits: 364

You can also test the admin panel. The password is: secretly. Feel free to add a link, I clear the database file every once in a while :)

Download the script

Version history

Version 1.0
Original ClickCounter.
Version 1.1
Database file managment slighly changed.
Version 2.0
Database file managment changed.
Improved security.
Added Show links option.
Version 2.1
Improved check for URL validity.

Database files from version 1 are not compatibile with version 2! If you decide to switch to a higher version, you will have to change the database file.

Installation

Step 1: Unzip the contents

Do this using some software, such as WinZip, WinRAR etc. If you have Windows XP you don't need any additional software.

Step 2: Modify the configuration file

No part of this script is allowed to be modified, except the config.php file. Open this file in a simple text editor (like Notepad). You will see instructions in form of comments, and some variables with values set. These are the default values:

$root = 'http://www.inobscuro.com';
$password = 'secretly';
$css = 'default.css';

Variable $root should be changed to your website root folder. The root folder is your website's address, but without the index.html or home.html or whatever. Just the folder, like in the above example.

Variable $password should be changed to whatever you want, but please use plain letters and numbers and make it shorter than 20 characters.

Variable $css doesn't have to be modified. You can keep the default CSS if you like it. I think it's quite nice ^_^ However, if you want to link to another external CSS file, just change the default.css to the full link to desired file (example: http://your.host.com/your_website/style.css).
Please, do not edit the default.css file. You can change the color values if you must, but please don't touch things like borders, padding, align etc. It's just right the way it is, trust me.

Step 3: Upload the files

Use some FTP program for this. If you don't know how to use FTP access, read the tutorial.

Upload the contents of the folder (not entire ClickCounterV1 folder, just contents inside this folder) to your root folder. This means the pages view.php and download.php must be in the same folder where your index.php and other files are. Now CHMOD the file click.db (in the folder click/data/) to 666 (rw-rw-rw-).
Now you've got it all set :)

Step 4: Managing links in database

Go to the URL http://your.website.com/click and if you did everything right, you should see a page stating "Click counter administration". Enter your password and click "enter". This will open a small panel with input fields for your links. The instructions say pretty much for themselves, but here it is in detail:
Do not use any unusual characters that could lead to confusion. If you do, the script may not work properly.
If the link is meant only for viewing (like affiliate links and other pages to be read, not downloaded), you don't have to enter the download URL, because you will never call the download.php for that entry anyway.
If the file is only ment for downloading (files that don't have a preview), you don't have to enter the view URL, same as above.
The initial count values are ment to be intact (that means left to 0), but if in some case something happens to the database file and you have to install the script over again, you may enter values bigger than 0. But please, don't cheat :) You're not fooling anyone by giving some file 10000 downloads, maybe you don't even have 10000 unique visitors ;P

When you entered all relevant data, click "add link" and the entry will be saved. The link's ID will be given to you.

Anyway, I strongly recommend that you often back up the click.db file to your hard disk, just in case, so you can easily upload the latest saved version if something goes wrong. Just remember the file must be CHMODed 666 each time you upload it.
If in some way you want to reset an entry count to zero or change URL, you'll have to do it manually (if you dare). The procedure:

  1. download the file to your hard disk (using a FTP program)
  2. open it in Notepad
  3. look for the desired entry name
  4. after the entry name the values are following: view URL, download URL, view count, download count. Change the value you need and save the file
  5. upload the file back and CHMOD to 666

Deleting entries is not possible because deleting a single value would seriously mess up the data file structure. Simply stop using that certain ID and don't worry about the database. You may delete the entry name to prevent it from appearing on the Show links page.

Step 5: Using view.php and download.php files

When you added links and got their ID's, now it's time to try out how they work. Change links on your HTML page, so instead of the real URL, they point to the script.
If the page is intended to be viewed, instead of linking to http://some.page.com/page.html make it link to view.php?id=1 , where 1 is the ID number of that certain link (change the ID number accordingly to each link).
If the file is to be downloaded, instead of linking to http://some.page.com/file.zip make it link to download.php?id=1 , where 1 is the ID number of that certain link (change the ID number accordingly).
Note that this will work only if view.php and download.php are in the same folder as the page you are clicking from. But, I hope you understand enough HTML to set up relative URLs if the files are not in the same folder.

Upload your pages and in the browser click the links you changed. After clicking on the link, you should be redirected to that certain page with a minimal delay. If you have been redirected to the page you wanted, it means the script is working good :) Otherwise, you might have messed something up while installing, or you entered the wrong URL in the database. Try out all the links and see how it works.

Step 6: Showing view/download count

So, you would probably want to show next to the link how many times it has been viewed/downloaded. In order for this to work, the HTML files you are changing must have the extension .php instead of .html. I hope you did that already.

In your webpage HTML code, move the cursor to the location where you want the view count to appear. Paste the following code to that location.

<?php $id=1; include('click/showviewcount.php'); ?>

Now look where the code says $id=1 . Change the number 1 to the real ID of that link.

The same goes for download count - paste this code where you want the download count to show:

<?php $id=1; include('click/showdownloadcount.php'); ?>

Also, change the number 1 to the real ID number.

This is it! :D
Upload your files on the server and go click around on the links and see what happens :) The view count and download count values should be changed for each click (you will have to refresh your page to see the changed count each time).
Now, if you were just trying out the script and you want to delete the links you added during this tutorial, upload the empty click.db file to the folder click/data/over the existing file to clear it. CHMOD to 666 and it's all set.
Add new URL's through the admin panel which is located on the address http://your.website.com/click (your.website.com being your real website address) and change your links according to what you learned in this tutorial ^_~

If you decided to use this script on your webpage, please give credit. It took a lot of effort to write both the script and this tutorial. Thank you :)

I hope you understood this tutorial well. Should you have any problems, feel free to contact me and I'll try to help.

Quick links

Network

RSS feeds

Affiliates

In obscuro — dark art and resources © 2004-2008 Nela Dunato. Terms of use

Back to top