drvpvmz16241016 2013-09-22 01:09
浏览 26
已采纳

基本PHP命中计数器[关闭]

So, I used to play with web development many years ago, and I'm a little rusty, but not THAT rusty!

I just made a full fledge video game page the other day using PHP variables to load different games into different size iframes. With that said, why on Earth can I not get a simple PHP hit counter to work? I have downloaded script after script after script, CHMOD'ed the txt file to 777, the whole 9. Does Chrome not support hit counters or something? It seems even the sites I visit that offer hit counters through them don't work on their demo pages!! What is the deal? I remember years ago, I copied about 10 very basic lines of code, saved it as a PHP file, uploaded it along with a blank txt file to a server, and bam, worked perfectly everytime. What has changed?

EDIT: Here's the code I'm using. By the way. I tried adding this into my index.html, I also tried using it as a separate php file and calling on it with INCLUDE, everything. Nothing seems to work. But the reason I asked without posting any code is because I'm using Chrome and it seemed like every site I visited that offered a hit counter was disfunctional and so I assumed that maybe after having read so many negative things about hit counters that maybe it wasn't something that was supported by script anymore?

<?php

$open = fopen(“hits.txt”, “r+”);
$value = fgets($open);
$close = fclose($open);

$value++;

$open = fopen(“hits.txt”, “w+”);
fwrite($open, $value); // variable is not restated, bug fixed.
$close = fclose($open);

?>

and then where I want the results to be displayed, I have,

<?php echo $value; ?>

Any ideas?

  • 写回答

1条回答 默认 最新

  • dongzhuo1930 2013-09-22 01:13
    关注

    a basic hit counter using a file as the saving point

    Script called myscript.php

    <?php
    $count = file_get_contents("/path/to/myscript_php_counter_file.txt");
    $count++;
    file_put_contents("/path/to/myscript_php_counter_file.txt",$count);
    
    //rest of script here.
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错