This is how I would go about doing what I think you are trying to do, using a mysql database.
Assuming that the table is already created, with the fields ID (int / auto-increment), IPAdd (text), VNum (int), and Recent (text).
<?php
##### MySQL Variables #####
$DB['name']="wwwwww";/// Database (replace wwwwww with database name)
$DB['host']="localhost";/// Host
$DB['user']="xxxxxx";/// Username (replace xxxxxx with username)
$DB['password']="yyyyyy";/// Password (replace yyyyyy with password)
$DB['table']="zzzzzz";/// Table (replace zzzzzz with table name)
$DB['connect']=mysql_connect($DB['host'], $DB['user'], $DB['password']) or die ('I cannot connect to the database because: ' . mysql_error());/// Connect to database
$DB['select']=mysql_select_db ($DB['name']) or die (mysql_error());/// Selects the Database to use
##### Database Queries #####
##### Put before HTML #####
$IP=$HTTP_SERVER_VARS["REMOTE_ADDR"];
$Query="SELECT * FROM ".$DB['table']." WHERE IPAdd='$IP' ";
$Result=@mysql_query($Query);
if ($Row =@mysql_fetch_assoc($Result)) {/// Go to record, if record exists
/// Update the table with the new values of vnum +1 and recent = today
$visit=$Row['vnum'];/// Gets the number of visits to site
$today=date("F j, Y, g:i");// Date formatting (Month Day, Year, Hour:Minute)
$QueryUpdate="UPDATE ".$DB['table']." SET vnum=". $visit+1 ." and recent=".$today." WHERE ipadd=".$IP."";
if (!mysql_query($QueryUpdate)) {///Query the database
mysql_error();/// Prints error message if mysql_query($QueryUpdate) fails
}
} else {
/// Create a record with the necessary values
$visit=1;///Since this is first visit, set visit number to 1
$today=date("F j, Y, g:i");/// Date formatting (Month Day, Year, Hour:Minute)
$QueryCreate="INSERT into ".$DB['table']." VALUES ('0', '".$IP."', '".$visit."', '".$today."')";
/// '0' will make the ID pick the next number in auto-index only if auto-increment has been set, else will error
if (!mysql_query($QueryCreate)) {///Query the database
mysql_error();/// Prints error message if mysql_query($QueryCreate) fails
}
}
?>
[B]Main Webpage Contents[/B]
<?
##### Disconnect from Database #####
##### Put at end of all code #####
if ($DB['connect']) {
mysql_close($DB['connect']);
}
?>
This should work as is, by just replacing the desired variables and whatnot. If it doesn't work, we can always tweak it.
Hope this helps !
🙂