Php image counter code-PHP source code

Source: Internet
Author: User
Ec (2); php image counter Code. Its implementation method is to first save the number to a txt file or database and then read it. Of course, we need to create a 0-9 image. now let's take a look at the statistical code. & lt ;? Php & nbsp; require_once (& quot ;.. incconnect. php & quot;); & nbsp; ClassSit_count {& nbsp; public $ FileNa script ec (2); script

Php image counter Code. Its implementation method is to first save the number to a txt file or database, and then read it. Of course, we need to prepare a 0-9 image. now let's take a look at the statistical code.

Require_once ("../inc/connect. php ");
Class Sit_count {
Public $ FileName = 'count.txt ';
Function Count_add (){
If (file_exists ($ this-> FileName )){
$ Temp = file_get_contents ($ this-> FileName );
$ Array = explode ("=", $ Temp );
If (count ($ Array )! = 2 ){
$ Tmp = 'mytext = '. $ this-> Tcount ();
} Else {
$ Total = $ Array [1] + 1;
$ Tmp = $ Array [0]. '='. $ Total;
}
$ T = @ fopen ($ this-> FileName, 'w ');
If ($ T ){
Fwrite ($ T, $ Tmp );
Fclose ($ T );
}
Mysql_query ("update wk_count set count_bak = count_bak + 1 where id = 1 ");
} Else {
Echo '! File_exists ';
}

}

Function Tcount (){
$ Result = mysql_query ("Select * from wk_count where id = 1") or die (mysql_error ());
$ Rs = mysql_fetch_array ($ result );
Return $ rs ['count _ Bak'];

}
}
$ Tp = new Sit_count;
$ Tp-> Count_add ();
?>
Now let's take a look at the output file of show. php.

$ Count = substr(file_get_contents('count.txt '), 7 );
$ Con_len = strlen ($ count );
For ($ I = $ con_len-1; $ I >=0; $ I --){
Echo "document. write ('');";
}

?>

In this way, our input counter will come out. Pay attention to this. echo "document. write ('');"; must begin with document. write output, because we need to call it in js format below.

The following figure shows how to call the show. php file in txt.html.

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.