Php multi-user counter code with a custom number of digits
Source: Internet
Author: User
This counter can customize any number of digits and display a simple advertisement for free.
During running, you need to create a datas directory under the counter directory where the nobody account has the permission to rewrite.
The actual running example is shown in
Http://www.hnpts.ha.cn/freecount.htm
<?
Header ("Content-type: image/png ");
If ($ user = "") $ user = "test ";
$ Fn = "datas/". $ user. ". txt ";
If ($ bit = "") $ bit = 8; // take the default value
If (is_readable ($ fn) {$ f = fopen ($ fn, "r ");
$ C = fgets ($ f, 255); fclose ($ f) ;}// read the original Count value
Else $ c = "0"; // new user
$ L = strlen ($ c); // calculate the actual value Length
$ Cnt = "";
For ($ I = 0; $ I <$ bit-$ l; $ I ++) $ cnt. = "0"; // Add "0" before to fill in the specified number of digits
$ Cnt. = $ c; $ c1 = intval ($ c); $ c1 ++;
$ F = fopen ($ fn, "w"); fputs ($ f, $ c1); fclose ($ f); // write back
$ Font = 20;
If ($ c1 % 10 = 9) & ($ user! = "Test") {$ cnt = "www.hnpts.ha.cn"; $ font = 16 ;}
// Display ads when conditions are met
$ S = ImageTTFBBox ($ font, 0, "times. ttf", $ cnt );
$ X = abs ($ s [4]) + 8; $ y = abs ($ s [5]) + 7;
$ Im = imagecreate ($ x, $ y );
$ Black = ImageColorAllocate ($ im, 0, 0 );
$ White = ImageColorAllocate ($ im, 255,255,255 );
If ($ font = 20) {$ green = ImageColorAllocate ($ im, 0,255, 0 );
Imagerectangle ($ im, $ X-2, $ y-2, $ white );}
Else $ green = ImageColorAllocate ($ im, 255,255,255 );
ImageTTFText ($ im, $ font, 0, 3, $ y-5, $ green, "times. ttf", $ cnt );
ImagePng ($ im );
ImageDestroy ($ im );
?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.