Тема: Прошу помощи в доработке скрипта под GetSimple
Доброго времени суток.
Имеется скрипт статистики который никак не могу докрутить до рабочего состояния и прошу помощи.
Подскажите что в этом скрипте не так.
counter.php
<?
$onlinetime="900"; //900 seconds=quarter hour
$base_dir=$_SERVER['DOCUMENT_ROOT'];
$ipfile=$base_dir . '/counter/ipfile.txt';
$datafile=$base_dir . '/counter/datafile.txt';
$date = date("j");
$date=trim($date);
$writefile=false;
$todayfulldate = date('l F j');
if ( isset($_SERVER["REMOTE_ADDR"]) ) {
$ip_address=$_SERVER["REMOTE_ADDR"] . ' ';
} else if ( isset($_SERVER["HTTP_X_FORWARDED_FOR"]) ) {
$ip_address=$_SERVER["HTTP_X_FORWARDED_FOR"] . ' ';
} else if ( isset($_SERVER["HTTP_CLIENT_IP"]) ) {
$ip_address=$_SERVER["HTTP_CLIENT_IP"] . ' ';
}
$ip_address=trim($ip_address);
//put your own IP address in here so that its not counted
if ($ip_address == '0.0.0.0') {
exit;
}
// open file and read in data
$file = fopen($datafile,"r");
$data=fgets($file);
fclose($file);
list ($today, $totalvisitors, $online, $visitorstoday, $visitorsyesterday, $twodaysago, $threedaysago, $mostvisitors, $mostvisitorsdate, $mostonline, $mostonlinedate, $hits) = explode("|", $data);
if ($today==0){$today=trim(date("j"));}
$hits++;
$total=0;
$online=0;
// Loop through our array
$lines=array();
$fp=fopen($ipfile, 'r');
while (!feof($fp)){
$line=fgets($fp);
$pieces = explode("|", $line);
//check if its current visitor and update time
if ($pieces[0]==$ip_address){
$line=$ip_address."|".time();
}
//add lines to array
if (time()-$pieces[1] <= $onlinetime){
$lines[$total]=$line;
$total++;
$online++;
}
//check if ip is already here
if ($ip_address==$pieces[0]){
$writefile=true;
}
//check if ipfile is empty and write first entry
if ($lines[0]==""){
$lines[0]=$ip_address . "|" . time();
$total++;
$writefile=true;
//set initial variables to 1
$today = $date;
$visitorstoday=1;
$totalvisitors=1;
$mostvisitors=1;
$mostvisitorsdate=$todayfulldate;
$mostonline=1;
$mostonlinedate=$todayfulldate;
}
}
fclose($fp);
$lines = array_unique($lines);
// write complete file and exit
if ($writefile==true){
$fp = fopen($ipfile, 'w');
if (flock($fp, LOCK_EX)) {
for ($i = 0; $i < $total; $i++){
fwrite($fp,$lines[$i]."\n");
}
$online=$i;
flock($fp, LOCK_UN);
}
fclose ($fp);
$fp = fopen($datafile, 'w');
if (flock($fp, LOCK_EX)) {
fwrite($fp, $today."|".$totalvisitors."|".$online."|".$visitorstoday."|".$visitorsyesterday."|".$twodaysago."|".$threedaysago."|".$mostvisitors."|".$mostvisitorsdate."|".$mostonline."|".$mostonlinedate."|".$hits);
flock($fp, LOCK_UN);
}
fclose($fp);
exit;
}
// append new ip to file
$online++;
$fp = fopen($ipfile, 'a');
if (flock($fp, LOCK_EX)) {
fwrite($fp, $ip_address . "|" . time() . "\n");
flock($fp, LOCK_UN);
}
fclose($fp);
//set date for first use
if ($mostonline==""){
$mostonline=1;
$today1 = date('l F j');
$mostonlinedate=$todayfulldate;
}
//most online date
if ($online > $mostonline){
$mostonline=$online;
$today1 = date('l F j');
$mostonlinedate=$todayfulldate;
}
//visitors
$totalvisitors++;
if ($today == $date){
$visitorstoday++;
if ($visitorstoday > $mostvisitors){
$mostvisitors=$visitorstoday;
$todayfulldate = date('l F j');
$mostvisitorsdate=$todayfulldate;
}
}else{
// change date if required
$today=$date;
$threedaysago=$twodaysago;
$twodaysago=$visitorsyesterday;
$visitorsyesterday=$visitorstoday;
$visitorstoday=1;
}
$fp = fopen($datafile, 'w');
if (flock($fp, LOCK_EX)) {
fwrite($fp, $today."|".$totalvisitors."|".$online."|".$visitorstoday."|".$visitorsyesterday."|".$twodaysago."|".$threedaysago."|".$mostvisitors."|".$mostvisitorsdate."|".$mostonline."|".$mostonlinedate."|".$hits);
flock($fp, LOCK_UN);
}
fclose($fp);
?>
showcount.php
<?
$base_dir=$_SERVER['DOCUMENT_ROOT'];
$datafile=$base_dir . '/counter/datafile.txt';
// open file and read in data
$file = fopen($datafile,"r");
$data=fgets($file);
fclose($file);
list ($today, $totalvisitors, $online, $visitorstoday, $visitorsyesterday, $twodaysago, $threedaysago, $mostvisitors, $mostvisitorsdate, $mostonline, $mostonlinedate, $hits) = explode("|", $data);
echo date("h:i:s A");
?>
<!-- STATS
<tr>
<td colspan=1 align:left>
Статистика от 05.09.2017<br/>
Сегодня: <?echo date('j F Y');?><hr>
</td>
</tr>
<tr>
<td style="text-align:left">Всего просмотров:</td>
<td style="text-align:right"><?echo $hits;?></td>
<tr>
<br/>
</tr>
<td style="text-align:left">Всего посетителей:</td>
<td style="text-align:right"><?echo $totalvisitors;?></td>
</tr>
<br/>
<tr>
<td style="text-align:left">Посетители онлайн:</td>
<td style="text-align:right"><?echo $online;?></td>
</tr>
<br/>
<tr>
<td style="text-align:left">Самые просматриваемые:<br><i>(<?echo $mostonlinedate;?>)</i></td>
<td style="vertical-align:top;text-align:right"><?echo $mostonline;?></td>
</tr>
<br/>
<tr>
<td style="text-align:left">Посетителей за день:<br><i>(<?echo $mostvisitorsdate;?>)</i></i></td>
<td style="vertical-align:top;text-align:right"><?echo $mostvisitors;?></td>
</tr>
<br/>
<tr>
<td style="text-align:left">Посетителей сегодня:</td>
<td style="text-align:right"><?echo $visitorstoday;?></td>
</tr>
<br/>
<tr>
<td style="text-align:left">Посетителей вчера:</td>
<td style="text-align:right"><?echo $visitorsyesterday;?></td>
</tr>
<br/>
<tr>
<td style="text-align:left">Два дня назад:</td>
<td style="text-align:right"><?echo $twodaysago;?></td>
</tr>
<br/>
<tr>
<td style="text-align:left">Три дня назад:</td>
<td style="text-align:right"><?echo $threedaysago;?></td>
</tr>
STATS --!>
Имеются еще 2 файла: datafile.txt и ipfile.txt
статистика на сайте видна но сам счетчик не считает.
Помогите разобраться в чем может быть проблема.