Hi Couch!
I want to use PHP code for counting unique visitors.
Unfortunately it does not work if it is surrounded by <cms:php> ... </cms:php>
This, however, need to be able to use <cms:show k_template_id /> to create text files for each page:
Original:
Mode:
However, this does not work ...
Here is the entire code:
Can you find a solution?
Regards
I want to use PHP code for counting unique visitors.
Unfortunately it does not work if it is surrounded by <cms:php> ... </cms:php>
This, however, need to be able to use <cms:show k_template_id /> to create text files for each page:
Original:
- Code: Select all
$lf_name = "hits.txt";
Mode:
- Code: Select all
$lf_name = "<cms:show k_template_id />.txt";
However, this does not work ...
Here is the entire code:
- Code: Select all
<?php
$lf_name = "hits.txt";
$monthly = 0;
$monthly_path = "oldfiles";
$type = 1;
$beforeTotalText = "Hits: ";
$beforeUniqueText = "Unique Visits: ";
$display = 1;
$separator = "<br \>";
$log_file = dirname(__FILE__) . '/' . $lf_name;
if ($_GET['display'] == "true") {
die("<pre><? include(\"" . dirname(__FILE__) . '/' . basename(__FILE__) . "\"); ?></pre>");
} else {
$uIP = $_SERVER['REMOTE_ADDR'];
if (file_exists($log_file)) {
$log = file_get_contents($log_file);
if ($monthly) { }
else {
if ($type == 0) {
$toWrite = intval($log) + 1;
$info = $beforeTotalText . $toWrite;
} else if ($type == 1) {
$hits = reset(explode(";", $log));
$IPs = end(explode(";", $log));
$IPArray = explode(",", $IPs);
if (array_search($uIP, $IPArray, true) === false) {
$hits = intval($hits) + 1;
$toWrite = $hits . ";" . $IPs . $uIP . ",";
} else { $toWrite = $log; }
$info = $beforeUniqueText . $hits;
} else if ($type == 2) {
// Separate log file into regular hits, unique hits, and IPs
$pieces = explode(";", $log);
$totalHits = $pieces[0];
$uniqueHits = $pieces[1];
$IPs = $pieces[2];
$IPArray = explode(",", $IPs);
$totalHits = intval($totalHits) + 1;
if (array_search($uIP, $IPArray, true) === false) {
$uniqueHits = intval($uniqueHits) + 1;
$toWrite = $totalHits . ";" . $uniqueHits . ";" . $IPs . $uIP . ",";
} else { $toWrite = $totalHits . ";" . $uniqueHits . ";" . $IPs; }
$info = $beforeTotalText . $totalHits . $separator . $beforeUniqueText . $uniqueHits;
}
write_logfile($toWrite, $info);
}
} else {
$fp = fopen($log_file, "w");
fclose($fp);
if ($type == 0) {
$toWrite = "1";
$info = $beforeTotxalText . "1";
} else if ($type == 1) {
$toWrite = "1;" . $uIP . ",";
$info = $beforeUniqueText . "1";
} else if ($type == 2) {
$toWrite = "1;1;" . $uIP . ",";
$info = $beforeTotalText . "1" . $separator . $beforeUniqueText . "1";
}
write_logfile($toWrite, $info);
}
}
function write_logfile($data, $output) {
global $log_file;
file_put_contents($log_file, $data);
if ($display == 1) { echo $output; }
}
?>
Can you find a solution?
Regards