duanping3587 2009-10-03 18:27
浏览 13
已采纳

Clicker计数器脚本无法正常工作!

I have this php code:

<?php
if(!file_exists('counter.txt')){
file_put_contents('counter.txt', '0');
}
if($_GET['click'] == 'yes'){
file_put_contents('counter.txt', ((int) file_get_contents('counter.txt')) + 1);
header('Location: ' . $_SERVER['SCRIPT_NAME']);
die;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>counter</title>
</head>
<body>
<h1><?php echo file_get_contents('counter.txt'); ?></h1>
<a href="?click=yes">clickMe</a>
</body>
</html>

It's supposed to count the amount of times someone clicks on a certain link.

I saved this code in a file called index.php, and then in the same directory I made a file called counter.txt(set the permissions of counter.txt to 666). However when I run the script it comes up with:

Fatal error: Call to undefined function: file_put_contents() in /home/index.php on line 6

How can I fix this error, and somehow display the count click on the same page as the link?

  • 写回答

1条回答 默认 最新

  • drsw9390405 2009-10-03 18:38
    关注

    If file_put_contents() is undefined, my guess is you're using a version of php < 5.

    If that is the case, you will need to replace that function with fopen(), fwrite() and fclose(), see also the php manual page.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了