Visitor Counter Slims 7
Visitor Counter Slims 7
Visitor Counter Slims 7
php
/**
*
* Visitor Counter
* Copyright (C) 2010 Arie Nugraha ([email protected])
* Modified By Eddy Subratha ([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
// be sure that this file not accessed directly
if (!defined('INDEX_AUTH')) {
die("can not access this file directly");
} elseif (INDEX_AUTH != 1) {
die("can not access this file directly");
}
$allowed_counter_ip = array('127.0.0.1');
$remote_addr = $_SERVER['REMOTE_ADDR'];
$confirmation = 0;
foreach ($allowed_counter_ip as $ip) {
// change wildcard
$ip = preg_replace('@\*$@i', '.', $ip);
if ($ip == $remote_addr || $_SERVER['HTTP_HOST'] == 'localhost' || preg_match("@$ip@i",
$ip)) {
$confirmation = 1;
}
}
if (!$confirmation) {
header ("location: index.php");
}
// start the output buffering for main content
ob_start();
define('INSTITUTION_EMPTY', 11);
if (isset($_POST['counter'])) {
if (trim($_POST['memberID']) == '') {
die();
}
$member_name = 'Guest';
$photo = 'person.png';
$expire = 0;
// sleep for a while
sleep(0);
/**
* Insert counter data to database
*/
function setCounter($str_member_ID) {
global $dbs, $member_name, $photo, $expire;
// check if ID exists
$str_member_ID = $dbs->escape_string($str_member_ID);
$_q = $dbs->query("SELECT member_id,member_name,member_image,inst_name,
IF(TO_DAYS('".date('Y-m-d')."')>TO_DAYS(expire_date), 1, 0) AS is_expire FROM member WHERE
member_id='$str_member_ID'");
// if member is already registered
if ($_q->num_rows > 0) {
$_d = $_q->fetch_assoc();
if ($_d['is_expire'] == 1) {
$expire = 1;
}
$member_id = $_d['member_id'];
$member_name = $_d['member_name'];
$member_name = preg_replace("/'/", "\'", $member_name);
$photo = trim($_d['member_image'])?trim($_d['member_image']):'person.png';
$_institution = $dbs->escape_string(trim($_d['inst_name']))?$dbs-
>escape_string(trim($_d['inst_name'])):null;