[Original] The simplest text counter-(it seems not simple, too exaggerated ~)

Source: Internet
Author: User
? Php $ filecount. dat; if (@ file_exists ($ file) {$ fp @ file ($ file); $ num $ fp [0]; $ ffopen ($ file, w + ); $ number $ num + 1; fputs ($ f, $ number);} else {$ ffopen ($ file, a +); fputs ($ fp, 0 );} @ fclose ($ f );? Hello? $ _ SERVER [REMOTE_ADDR]?, You are the number [? $ Number?] Location counter

$ File = "count. dat ";
If (@ file_exists ($ file )){
$ Fp = @ file ($ file );
$ Num = $ fp [0];
$ F = fopen ($ file, "w + ");
$ Number = $ num + 1;
Fputs ($ f, $ number );
} Else {
$ F = fopen ($ file, "a + ");
Fputs ($ fp, "0 ");
}
@ Fclose ($ f );
?>
Hello , You are [ ] Guest

Encapsulated
Class Counter {
Function addnumber (){
// Multi-user function addnumber ($ user) {// prompt: you can use the ID to count multiple users (multi-page), for example, $ c = new Counter; $ c-> addnumber ($ id );
$ File = "count. dat ";
// Multiple users (page) $ file = $ user. ". dat ";
If (@ file_exists ($ file )){
$ Fp = @ file ($ file );
$ Num = $ fp [0];
$ F = fopen ($ file, "w + ");
$ Number = $ num + 1;
Fputs ($ f, $ number );
} Else {
$ F = fopen ($ file, "a + ");
Fputs ($ fp, "0 ");
}
@ Fclose ($ f );
Print ("Hello $ _ SERVER [" REMOTE_ADDR "], you are the [$ number] guest on this site ");
}
}

Call
Eg. php
$ Co = new Conter;
$ Co-> addnumber (); // count a single user
$ Co-> addnumber ($ id); // multi-user (page) count. the ID here can be the user id that matches the record in your database, or you can remove PHP_SELF from the directory, haha, put a counter directory separately. each page (user) has its own name. dat file to record his
Page access Volume ~, You can also do simple things ~
?>

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.