Hello if i visit my page lets say http://mydomain.com/25 when someone visits this page there should be a number added to 25.txt so if there is a 0 in that txt file it should become 1. +1 each time basiclly. And if 25.txt do not exist it should be created, can this be done somehow in either php/html ?
Hello well , its possible, and can be achieved easily, but i think why to write in a File, i would recommend using a Database...but if you want to get it done in file , its ok, it can be done..you need to follow simple login , 1) Check the last part of url hxxp://mydomain.com/25 , which is 25 in this case...Store it in a variable say $filename. 2) use php file handling function to check if the file exists or not, 3) if exists , read the file(one line only), and check if its number or not and increment it .and save it to file... you are done 4)and if the file doesnt exists create the file , and store 1 in the file, and close the file.... Hope this helps, it wont be difficult to accomplish this, but if you need any help ,let me know, ill try to post the code for you... Cheers
Why not files? Files are great and in many cases outperform database. So I'd implement it with .htaccess and simple script. Something like this: .htacess: RewriteEngine On RewriteRule ^([0-9]+)$ counter.php?id=$1 [L] Code (markup): counter.php: <? $id = $_GET["id"]; $fname = sprintf("%d.txt", $id); $f = fopen($fname, 'c+'); if(flock($f, LOCK_EX )) { $data = fread($f, filesize($fname)?filesize($fname):1); $data = intval($data) + 1; ftruncate($f, 0); rewind($f); fwrite($f, $data); flock($f, LOCK_UN); } ?> Code (markup): Just basic idea
Hello Well this Idea is also nice...and easy to implement,But i just gave information about it and option to use Database too, and i agree in some cases files outperforms database, but for the rest we have to use Database.. Btw your Coding style is nice.. I like it...
Thank you, sourabhj. You are completely right on databases. In many cases they are more simple to use and implement more complex things.