Put counters and calendars in *. htm or *. html files

Source: Internet
Author: User
Generally, you need to put your own text counters or calendars in the * .php file. if you want to use htmor htmlfor file extension names (such as index.html), can you still store counters or calendars? The answer is yes. The method is to use the PHP graphic output function to draw the desired image, and use the HTTP header information to make the html file SyntaxHighlighter.

Generally, you need to put your own text counters or calendars in the * .php file. if you want to use htmor htmlfor file extension names (such as index.html), can you still store counters or calendars? The answer is yes. The method is to use the PHP graphic output function to draw the desired image, and then use the HTTP header information so that the html file can treat this PHP file as a graphical file, in *. htm or *. placing counters or calendars in html files is as easy as placing an image file! The following is the php source code of the counter graphics file count. php and the calendar file date. PHP:

--------------- File count. php (counter )----------
If (! File_exists ("count.txt "))
Exec ("echo 0> count.txt ");
$ Fp = fopen ("count.txt", "r + ");

$ FileSize = filesize ("count.txt ");
$ Count = fgets ($ fp, $ FileSize + 1 );

$ Count + = 1;
Fseek ($ fp, 0 );
Fputs ($ fp, $ Count );
Fclose ($ fp );

$ StrCount = strval ($ Count); // Convert the obtained Count to a string
$ StrCount = Chop ($ strCount );
$ CountLen = strlen ($ strCount );

For ($ I = 0; $ I <8-$ CountLen; $ I ++) // The counter is set to 8 bits. if it is not enough, it is set to zero.
$ StrCount = "0". $ strCount;

// Create an image
$ Img = imagecreate (90, 26 );

// Match the color
$ Black = imagecolorallocate ($ img, 0, 0, 0 );
$ Green = imagecolorallocate ($ img, 0,255, 0 );


$ Fgray = imagecolorallocate ($ img, 180,180,180 );
$ Dgray = imagecolorallocate ($ img, 130,130,130 );
$ Gray = imagecolorallocate ($ img, 160,160,160 );

// Draw a border
Imagerectangle ($ img, 0, 0, 89, 25, $ fgray );
Imagerectangle ($ img, 1, 1, 88, 24, $ dgray );
Imagerectangle ($ img, 2, 2, 87, 23, $ gray );

// Output count
Imagestring ($ img, 4, 13, 5, $ strCount, $ green );

// Output image
Header ("Content-type: image/png ");
Imageinterlace ($ img, 1 );
Imagepng ($ img );
?>


--------------- File date. php (calendar )----------------------------
// Create an image
$ Img = imagecreate (132, 26 );

// Match the color
$ Black = imagecolorallocate ($ img, 0, 0, 0 );
$ Green = imagecolorallocate ($ img, 0,255, 0 );
$ Fgray = imagecolorallocate ($ img, 180,180,180 );
$ Dgray = imagecolorallocate ($ img, 130,130,130 );
$ Gray = imagecolorallocate ($ img, 160,160,160 );

// Draw a border
Imagerectangle ($ img, 0, 0,131, 25, $ fgray );
Imagerectangle ($ img, 1, 1,130, 24, $ dgray );
Imagerectangle ($ img, 2, 2,129, 23, $ gray );

// Output date
Imagestring ($ img, 4, 11, 5, date ("Y. m. d. D"), $ green );

// Output image
Header ("Content-type: image/png ");
Imageinterlace ($ img, 1 );
Imagepng ($ img );
?>

As long as these two files are inserted anywhere in the HTML file as graphical files, they become counters and calendars. you can go to the following address to see the effect:
Http://youziyun.oso.com.cn

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.