Browse Source

another attempt fixing the lose of stats

remotes/origin/HEAD v3.1.0
René Wagner 10 months ago
parent
commit
67ae933690
  1. 14
      index.php
  2. 17
      redirect.php

14
index.php

@ -8,8 +8,18 @@ $stats_path = implode(DIRECTORY_SEPARATOR, array(__DIR__, "data", "stats.json"))
$stats_content = json_decode(file_get_contents($stats_path), true);
// Count the access
$stats_content["index"][date("Y-m-d")] += 1;
file_put_contents($stats_path, json_encode($stats_content, JSON_PRETTY_PRINT), LOCK_EX);
$statsfile = fopen($stats_path, 'c+');
if (flock($statsfile, LOCK_EX))
{
$stats_content = json_decode(fread($statsfile, filesize($stats_path)), true);
$stats_content["index"][date("Y-m-d")] += 1;
ftruncate($statsfile, 0);
fseek($statsfile, 0);
fwrite($statsfile, json_encode($stats_content, JSON_PRETTY_PRINT));
flock($statsfile, LOCK_UN);
}
fclose($statsfile);
// Generate custom buttons for the footer
$links_string = "";

17
redirect.php

@ -17,10 +17,19 @@ $stats_path = implode(DIRECTORY_SEPARATOR, array(__DIR__, "data", "stats.json"))
// Count the access to the given $name
function count_access($name) {
global $stats_path;
$stats_content = json_decode(file_get_contents($stats_path), true);
$stats_content[$name][date("Y-m-d")] += 1;
file_put_contents($stats_path, json_encode($stats_content, JSON_PRETTY_PRINT), LOCK_EX);
$statsfile = fopen($stats_path, 'c+');
if (flock($statsfile, LOCK_EX))
{
$stats_content = json_decode(fread($statsfile, filesize($stats_path)), true);
$stats_content[$name][date("Y-m-d")] += 1;
ftruncate($statsfile, 0);
fseek($statsfile, 0);
fwrite($statsfile, json_encode($stats_content, JSON_PRETTY_PRINT));
flock($statsfile, LOCK_UN);
}
fclose($statsfile);
}
if (array_key_exists($short, $config_content["shortlinks"])) {

Loading…
Cancel
Save