Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to...

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Ok, I've got the idea in my head, but I'm not completly sure how to set it up.

Basically, I have a file with a number in (to count something). Every time someone submit a form, this number needs to increment. I know about the $count++ option, and the file() one to get the contents of the file, but I'm not quite so sure about the reading of the file (I always forget stuff like rewind).

If anyone could give me some codes, or examples, to use...that would be great :

Thanks

Andy
 
As simple as this:

$fp=fopen("filename.txt","w+");
$flock($fp,LOCK_EX);
$number=fread($fp,filesize("filename.txt"));
rewind($fp);
fprintf($fp,++$number);
flock($fp,LOCK_UN);
fclose($fp);

Not tested, but the ideas are here

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top