In this article I assume you have read my previous articles and know some WhizBase basics, as how to query, insert or update a DB.
We will need one table in the DB where we will keep the data of the recent visitors. The principle goes like this:
1- the visitor enters the site
2- we check the IP address of visitor and check if he is in the DB
3- if the IP exists, we update its record with current time
4- if not, we insert a new record
5- To include to visitor in our counting he must check-in in last 5 seconds
The database table used by the tutorial
I will not go through the SQL or the Access file creation, I will just describe what we need in the DB. We will need one table named “visitor”. It will have the following fields:
Id as integer(9) autoincrement primary key
IP as char(100) unique and not null
Lastvisit as DateTime
I will create it in access DB and name the file visitor.mdb, and the table as visitor.
The id is auto increment field, so we will not need it in our code, it is just for table indexing and maintenance. The IP is the IP address of the visitor, and it must be unique and not null. Lastvisit will be a date and time of the last visit.
If exists include update, else include add
As we stated in the introduction, we will need to check if the visitor is online or not, and then include the file which makes the needed changes on the DB.
[FormFields]
WB_BaseName=visitor.mdb
WB_RcdSet=visitor
WB_Query=IP=$WBE{REMOTE_ADDR}
WB_Command=Q
<!–WB_BeginTemplate–>
$WBIF[$WBP[RC]>0|
$WBGETURL[update.wbsp?wbf_id=$WBF[id]]
|
$WBGETURL[add.wbsp?wbf_ip=$WBE[REMOTE_ADDR]]
]
<html>
<head>Number of visitors online</head>
<body>
$wbsr[show.sr]
</body>
</html>
In this code we have started WhizBase file and queried the DB
For more information email me at: NurAzije [at] Gmail [dot] comOr visit WhizBase official site at www.whizbase.comNurAzije is a PHP and WhizBase programmer, who at the time of article publication is working in partnership with WhizBase on several projects.
Article Source