I need to setup a simple counter for my outbound link page, redirect.php. My basic php knowledge can increment a number in a txt file everytime somebody clicks through redirect.php - but is there a more elegant way?
A simple txt based solution would look like this. Just create a file called count.txt to the same directory where your code is located. if(file_exists("count.txt")) { $file = fopen("count.txt", "r"); $count = fgets($exist_file, 255); $count++; fclose($file); $file= fopen("count.txt", "w"); fwrite($file, $new_count); fclose($file); } PHP: However I'd advise you to go for a database driven solution. Do you have MySql on your webserver?
Create count.txt, Chmod 777. Better code. if(file_exists("count.txt")) { $count = file_get_contents('count.txt'); $count++; $file= fopen("count.txt", "w"); fwrite($file, $count); fclose($file); } PHP: Jay