In this article, I'll demonstrate how to create a very simple-counter for a web (WebCounter).

First of all, prepare the database - more accurately, create the necessary tables.

The table name will be "counter" and will have two columns: "id" - number of records to be added and automatically zoom in for each record in a table and "address" - IP addresses of visitors.

To do this, use the following SQL code (maybe you know where it is contracting;)):

Code: SQL
Code:
CREATE TABLE counter (id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, address VARCHAR (15))
Now let's go on to our script. Generally, the script will work like this: Verifies whether an IP address is not yet in the database (which is the case of a new visitor), or IP address we already have (which means that the visitor was already here). In the first case, add a database to record and extract the highest "id", in the second case, just dump the "id".

Code: PHP
$ Remote_ip = $ _SERVER ['REMOTE_ADDR']; / / find the IP
/ / We are looking for it in the database:
$ Sql_query = "SELECT * FROM counter WHERE address = '$ remote_ip'";
$ Sql_res = mysql_query ($ sql_query);
/ / If the first time here - not a record:
if (mysql_fetch_array ($ sql_res)) {
/ / Add it to DB
$ Sql_query = "INSERT INTO counter (address) VALUES ('$ remote_ip')";
mysql_query ($ sql_query);
/ / Get the highest id
$ Id = mysql_fetch_array (mysql_query ("SELECT MAX (id) FROM counter"));
/ / And extract it:
echo "You are visitor #". $ id ['MAX (id)'];
} Else {/ / when he returns (which put to other cases) ...
/ / Get the highest id:
$ Count = mysql_fetch_array (mysql_query ("SELECT MAX (id) FROM counter"));
echo "You are visitor #". $ count ['MAX (id)'] / / and extract it
}

Do not forget to connect to database server (mysql_connect ('server', 'user', 'pass')), and select the database (mysql_select_db ('db_name')).

Of course, this simple code can be extended to - You can add there a last visit func, or counter of the views, etc.

P. S. I apologize for the terrible grammar ..., I had no time to correct it :(

Stay tuned for the further Articles!