创建一个名为counter.php的文件并将以下代码放入其中: <?php //计数器 $ count_my_page =(" hitcounter.txt"); $ hits = file($ count_my_page); $ hits [0] ++; $ hit_count = $ hits [0]; $ fp = fopen($ count_my_page," w"); fputs($ fp," $点击[0]"); fclose($ fp); // echo $ hits [0]; //要添加到列表的详细信息 $ count_my_page =(" hitcounter.csv"); $ fp = fopen($ count_my_page," a"); $ ip = $ _ SERVER [REMOTE_ADDR]; $ dnsname = gethostbyaddr($ ip); $ referer = $ _ SERVER [HTTP_REFERER] ; $ page = $ _ SERVER [PHP_SELF]; $ now = date(" Y / m / d H:i:s",time()); fputs($ fp," $ now,$ hit_count,$ page,$ ip,$ dnsname,$ referer \\ r \\ n \\ n; \\ n \\ n \\ n; \\ n> fclose($ fp); ?> 然后创建一个名为的文件hitcounter.txt并将值0放入其中。 然后创建一个名为hitcounter.csv的文件并在其中放入以下文本: TimeStamp,Count,Page ,IP-Adress,DNS,Referer 请记住给你的 本地互联网帐户的hitcounter文件写入权限并完成。 现在,在每个PHP网页上,您都需要在 < header>< / headeror< body>< / bodytags: <?php include(" counter.php"); ?> 如果您在单击csv文件时将.csv文件链接到excel,您将承诺将使用excel打开它。 如果你得到一个很好的数据网格布局。 To make this work on a single page you will need to create/modify 4files.So here goes... Create a file called counter.php and put following code in it:<?php//Counter$count_my_page = ("hitcounter.txt");$hits = file($count_my_page);$hits[0] ++;$hit_count = $hits[0];$fp = fopen($count_my_page , "w");fputs($fp , "$hits[0]");fclose($fp);//echo $hits[0]; //Details to add to list$count_my_page = ("hitcounter.csv");$fp = fopen($count_my_page , "a");$ip=$_SERVER[REMOTE_ADDR];$dnsname = gethostbyaddr($ip);$referer=$_SERVER[HTTP_REFERER];$page=$_SERVER[PHP_SELF];$now = date( "Y/m/d H:i:s", time() );fputs($fp , "$now,$hit_count,$page,$ip,$dnsname,$referer\r\n") ;fclose($fp);?> Then create a file called hitcounter.txt and put value 0 in it. Then create a file called hitcounter.csv and put following text in it:TimeStamp,Count,Page,IP-Adress,DNS,Referer Remember to give write permitions to the hitcounter files for yourlocal internet account and you done. Now on every PHP web page you have add the following code between the<header></headeror <body></bodytags:<?php include ("counter.php"); ?> If you link .csv file to excel when you click on the csv file you willbe promted to open it with excel.If you do you get a nice grid layout of the data.推荐答案 count_my_page =(" hitcounter.txt") ; count_my_page = ("hitcounter.txt"); hits = file(hits = file( count_my_page); count_my_page); 这篇关于为PHP网页创建一个简单的hitcounter。 (保存到文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-23 10:42