OK so I've adapted some code I found to hopefully record a click event and display it live in my wordpress site, but it isn't working. here is the code I've written. This is my fist attempt at writing code in general. Can anyone see where i'm going wrong?
doing_totalcount.php
<?php
if (onclick"<a href="#" class="menu-link">EDGE</a>($counters_folder . md5($file) . '_counter.txt')) {
$fp = fopen($counters_folder . md5($file) . '_counter.txt', "r");
$count = fread($fp, 1024);
fclose($fp);
$fp = fopen($counters_folder . md5($file) . '_counter.txt', "w");
fwrite($fp, $count + 1);
fclose($fp);
} else {
$fp = fopen($counters_folder . md5($file) . '_counter.txt', "w+");
fwrite($fp, 1);
fclose($fp);
}
?>
count_totalcount.php
<?php
function get_totalcount_count($file = null) {
$counters = $_SERVER['DOCUMENT_ROOT'] . '/files/counter/';
if ($file == null) return 0;
$count = 0;
if (file_exists($counters . md5($file) . '_counter.txt')) {
$fp = fopen($counters . md5($file) . '_counter.txt', "r");
$count = fread($fp, 1024);
fclose($fp);
} else {
$fp = fopen($counters . md5($file) . '_counter.txt', "w+");
fwrite($fp, $count);
fclose($fp);
}
return $count;
}
?>
call_totlcount.php
<?php
include($_SERVER["DOCUMENT_ROOT"] . "/php/count_totalcount.php");
$item['lifetime'] = get_totalcount_count;
echo json_encode($item);
?>
static_totalcount.php
<?php
include($_SERVER["DOCUMENT_ROOT"] . "/php/count_totalcount.php");
$item['lifetime'] = get_totalcount_count;
?>
totalcount.js
$(document).ready(function() {
$.ajaxSetup({cache: false});
getStatus();
});
function getStatus() {
$.getJSON('php/call_totalcount.php', function(data) {
$('#lifetime').html(data.lifetime);
});
setTimeout("getStatus()",1000);
}
index.php
<?php include($_SERVER["DOCUMENT_ROOT"] . "/php/static_totalcount.php"); ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Landing page</title>
<script type="text/javascript" src="jsc/jquery.min.js"></script>
<script type="text/javascript" src="jsc/totalcount.js"></script>
</head>
<body>
You have clicked the button <span id="lifetime"><?php echo $item['lifetime']; ?></span> Times<br />
</body>
</html>
This is the link to the original question that i took the code from, so you can see what I changed so it was relevant to my needs
PHP making a download counter without leaving the current page