i would like to program a hit counter
well thats exactly how php came into being in the first place
how many times a file has been downloaded by original users
ok php only exists and runs for the page request... so you will need to store this info somewhere outside of php... so each time php does exist.. it can grab the info from somewhere
you want a mapping of: file => ip_address
OK perfect for sql... not so good for writing to just some flat file
1) get a sql server: two free sql servers are PostGre Sql (my recommendation) and MySql (the standard)
2) you will need to make a database inside sql that will hold your information
3) you will need to make a table inside that databse to hold your relationship of file to ip_address
Table: FileHits
column 1: file_path varchar(500): assuming up to 500 characters in the path: holds the file you are talking about
column 2: ip_address varchar(71): assume an ipv4 (19 chars) or ipv6 (up to 71 chars) address, MAC addresses not considered: holds the unique user you are talking about
column 3: hit_count int unsigned: positive only integer
read up on the php functions which allow you to do database access from inside php
Postgres:[man]pgsql[/man] and Mysql:[man]mysql[/man]
now you can ask sql questions like... how many total hits has this:
$this_file = $_SERVER['PHP_SELF'];
$sql = "
SELECT
SUM(hit_count)
FROM
FileHits
WHERE
file_path = '$this_file'
";
$number_of_hits = some_function_which_runs_your_sql( $sql );
or how many times this user has been here:
$this_file = $_SERVER['PHP_SELF'];
$ip_address = $_SERVER['REMOTE_ADDR'];
$sql = "
SELECT
hit_count
FROM
FileHits
WHERE
file_path = '$this_file'
AND
ip_address = '$users_ip_address'
";
$number_of_hits = some_function_which_runs_your_sql( $sql );
now with these examples and the php.net manual and its examples.. you should be hit counting in a few hours