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?