| Server IP : 208.122.213.31 / Your IP : 216.73.216.45 Web Server : Apache System : Linux msd6191.mjhst.com 4.18.0-553.137.1.el8_10.x86_64 #1 SMP Wed Jun 24 11:40:24 UTC 2026 x86_64 User : WHMCS_MIA_382 ( 1001) PHP Version : 7.4.33 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/httpd/html/tits-bigtits.com/phphits/ |
Upload File : |
<?php
/*
***************************************************
***************************************************
* phphits v1.1 Beta :: shared functions *
* Coded by Johannes Gamba (jgamba@geekfactory.de) *
***************************************************
***************************************************
*/
/*
*************************************************************************
DO NOT CHANGE ANYTHING BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING!
*************************************************************************
*/
// ~~~~~ Include settings ~~~~~
include_once("settings.inc.php");
// ~~~~~ Misc. settings ~~~~~
define("SCRIPT_VERSION", "1.1 Beta");
// **********************************************************************
function dbConnect()
{
if (!($sql_id = @mysql_connect(SQL_HOST, SQL_USER, SQL_PWD)))
{
return 0;
}
if (!(@mysql_select_db(SQL_DB, $sql_id)))
{
return 0;
}
return $sql_id;
}
// **********************************************************************
function dbRunQuery($sql_id, $sql_query)
{
if (!($sql_result = @mysql_query($sql_query, $sql_id)))
{
return 0;
}
return $sql_result;
}
// **********************************************************************
function dbDisconnect($sql_id, $sql_result)
{
@mysql_free_result($sql_result);
@mysql_close($sql_id);
}
// **********************************************************************
function phphitsAddHit()
{
// ~~~~~ Get current timestamp ~~~~~
$u_timestamp = time();
// ~~~~~ Get visitor's IP, ignore hit if IP is blocked ~~~~~
if (@getenv("HTTP_X_FORWARDED_FOR"))
{
$u_ip = @getenv("HTTP_X_FORWARDED_FOR");
}
else
{
$u_ip = @getenv("REMOTE_ADDR");
}
if ($u_ip == COUNTER_BLOCK_IP)
{
return 1;
exit;
}
// ~~~~~ Get visitor's host name ~~~~~
$u_host = "";
if (COUNTER_REC_HOST)
{
$u_host = @gethostbyaddr($u_ip);
}
// ~~~~~ Get visitor's browser type (HTTP headers) ~~~~~
$u_browser = "";
if (COUNTER_REC_BROWSER)
{
$u_browser = @getenv("HTTP_USER_AGENT");
}
// ~~~~~ Get visitor's user language (HTTP headers) ~~~~~
$u_lang = "";
if (COUNTER_REC_LANGUAGE)
{
$u_lang = @explode(",", @getenv("HTTP_ACCEPT_LANGUAGE"));
$u_lang = @strtolower($u_lang[0]);
}
// ~~~~~ Get page where visitor came from (referrer) ~~~~~
$u_referrer = "";
if (COUNTER_REC_REFERRER)
{
$u_referrer = @getenv("HTTP_REFERER");
}
// ~~~~~ Get name of page visitor is looking at ~~~~~
$u_page = "";
if (COUNTER_REC_PAGE)
{
$u_page = @getenv("SCRIPT_NAME");
}
// ~~~~~ Connect to MySQL server, activate database ~~~~~
if (!($sql_id = dbConnect()))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_connect", $sql_id);
}
// ~~~~~ Get number of matching rows from MySQL log table, exit if visitor was already counted ~~~~~
if (!($sql_result = dbRunQuery($sql_id, "SELECT COUNT(*) FROM " . SQL_TABLE_LOG . " WHERE (ip LIKE \"%" . $u_ip . "%\") AND (tstamp + " . (COUNTER_BLOCK_TIME * 60) . " > " . $u_timestamp . ")")))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_select", $sql_id);
}
$sql_numrows = @mysql_result($sql_result, 0);
if ($sql_numrows > 0)
{
dbDisconnect($sql_id, $sql_result);
return $sql_result;
exit;
}
// ~~~~~ Update counter table, insert new row with information on visitor into MySQL log table ~~~~~
if (!($sql_result = dbRunQuery($sql_id, "UPDATE " . SQL_TABLE_COUNTER . " SET hits=(hits+1) WHERE rowid=1")))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_update", $sql_id);
}
if (!($sql_result = dbRunQuery($sql_id, "INSERT INTO " . SQL_TABLE_LOG . " (ip,host,browser,language,referrer,page,tstamp) VALUES (\"$u_ip\",\"$u_host\",\"$u_browser\",\"$u_lang\",\"$u_referrer\",\"$u_page\",\"$u_timestamp\")")))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_insert", $sql_id);
}
// ~~~~~ Delete older hits in log table (if necessary) ~~~~~
if (SQL_LOG_HITS <> "0")
{
$sql_result = dbRunQuery($sql_id, "SELECT rowid FROM " . SQL_TABLE_LOG . " ORDER BY rowid desc LIMIT 1");
if (!($sql_result = dbRunQuery($sql_id, "DELETE FROM " . SQL_TABLE_LOG . " WHERE rowid <= (" . @mysql_result($sql_result, 0) . " - " . SQL_LOG_HITS . ")")))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_delete", $sql_id);
}
}
// ~~~~~ Free memory, close connection to MySQL server ~~~~~
dbDisconnect($sql_id, $sql_result);
return $sql_result;
}
// **********************************************************************
function phphitsShowLog($sortby, $mode)
{
// ~~~~~ Set general variables ~~~~~
if ($mode == "desc")
{
$mode_link = "asc";
}
else
{
$mode_link = "desc";
}
// ~~~~~ Connect to MySQL server, activate database ~~~~~
if (!($sql_id = dbConnect()))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_connect", $sql_id);
}
// ~~~~~ Get rows from MySQL log table ~~~~~
$sql_query = "SELECT rowid,ip,host,browser,language,referrer,page,tstamp FROM " . SQL_TABLE_LOG . " ORDER BY " . $sortby . " " . $mode;
if (LOG_NUM_HITS <> 0)
{
$sql_query .= " LIMIT " . LOG_NUM_HITS;
}
if (!($sql_result = dbRunQuery($sql_id, $sql_query)))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_select", $sql_id);
}
// ~~~~~ Get number of rows in MySQL result ~~~~~
$sql_numrows = @mysql_num_rows($sql_result);
// ~~~~~ Output some HTML code ~~~~~
echo "<b>php</b><i>hits</i> v" . SCRIPT_VERSION . " :: log file";
echo "<hr noshade><br>";
echo "<b>" . $sql_numrows . " hits stored in log table [<a href=\"stats.php?a_user=" . md5(ADMIN_USER) . "&a_pwd=" . md5(ADMIN_PWD) . "\">View stats</a>]</b><p></p>";
echo "\n<table width=\"100%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#cccccc\">\n";
echo "<tr height=\"25\" bgcolor=\"#dddddd\">\n";
echo "\t<td><b><a href=\"log.php?sortby=rowid&mode=" . $mode_link . "&a_user=" . md5(ADMIN_USER) . "&a_pwd=" . md5(ADMIN_PWD) . "\">Nr.</a></b></td>\n";
echo "\t<td><b><a href=\"log.php?sortby=tstamp&mode=" . $mode_link . "&a_user=" . md5(ADMIN_USER) . "&a_pwd=" . md5(ADMIN_PWD) . "\">Date | Time</a></b></td>\n";
echo "\t<td><b><a href=\"log.php?sortby=ip&mode=" . $mode_link . "&a_user=" . md5(ADMIN_USER) . "&a_pwd=" . md5(ADMIN_PWD) . "\">IP</b></a></td>\n";
echo "\t<td><b><a href=\"log.php?sortby=host&mode=" . $mode_link . "&a_user=" . md5(ADMIN_USER) . "&a_pwd=" . md5(ADMIN_PWD) . "\">Host</b></a></td>\n";
echo "\t<td><b><a href=\"log.php?sortby=browser&mode=" . $mode_link . "&a_user=" . md5(ADMIN_USER) . "&a_pwd=" . md5(ADMIN_PWD) . "\">Browser</b></a></td>\n";
echo "\t<td><b><a href=\"log.php?sortby=language&mode=" . $mode_link . "&a_user=" . md5(ADMIN_USER) . "&a_pwd=" . md5(ADMIN_PWD) . "\">Lang.</b></a></td>\n";
echo "\t<td><b><a href=\"log.php?sortby=referrer&mode=" . $mode_link . "&a_user=" . md5(ADMIN_USER) . "&a_pwd=" . md5(ADMIN_PWD) . "\">Referrer</b></a></td>\n";
echo "\t<td><b><a href=\"log.php?sortby=page&mode=" . $mode_link . "&a_user=" . md5(ADMIN_USER) . "&a_pwd=" . md5(ADMIN_PWD) . "\">Page</b></a></td>\n";
echo "</tr>\n";
while ($sql_row = @mysql_fetch_array($sql_result))
{
if ((time() - $sql_row["tstamp"]) <= (LOG_HIGHLIGHT_TIME * 3600))
{
echo "<tr bgcolor=\"" . LOG_HIGHLIGHT_COLOR . "\">\n";
}
else
{
echo "<tr>\n";
}
echo "\t<td>" . $sql_row["rowid"] ."</td>\n";
echo "\t<td>" . date("Y.m.d H:i:s", $sql_row["tstamp"]) . "</td>\n";
echo "\t<td>" . $sql_row["ip"] . "</td>\n";
echo "\t<td>" . $sql_row["host"] . "</td>\n";
echo "\t<td>" . $sql_row["browser"] . "</td>\n";
echo "\t<td>" . $sql_row["language"] . "</td>\n";
if (@strlen($sql_row["referrer"]) > 60)
{
echo "\t<td><a href=\"" . $sql_row["referrer"] . "\" target=\"_blank\">" . @substr($sql_row["referrer"], 0, 60) . "..." . "</a></td>\n";
}
else
{
echo "\t<td><a href=\"" . $sql_row["referrer"] . "\" target=\"_blank\">" . $sql_row["referrer"] . "</a></td>\n";
}
echo "\t<td><a href=\"" . $sql_row["page"] . "\" target=\"_blank\">" . $sql_row["page"] . "</a></td>\n";
echo "</tr>\n";
}
echo "</table><br>\n";
echo "<i>Hits within the last " . LOG_HIGHLIGHT_TIME . " hours are highlighted.</i><p></p>";
echo "<hr noshade>";
echo "<font color=\"999999\"><b>Coded by <a href=\"mailto:jgamba@geekfactory.de?subject=phphits\">Johannes Gamba</a></b></font>";
// ~~~~~ Free memory, close connection to MySQL server ~~~~~
dbDisconnect($sql_id, $sql_result);
return $sql_result;
}
// **********************************************************************
function phphitsShowOnlineUsers()
{
// ~~~~~ Connect to MySQL server, activate database ~~~~~
if (!($sql_id = dbConnect()))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_connect", $sql_id);
}
// ~~~~~ Get number of matching rows from MySQL table ~~~~~
if (!($sql_result = dbRunQuery($sql_id, "SELECT COUNT(*) FROM " . SQL_TABLE_LOG . " WHERE (tstamp + " . (COUNTER_USERONLINE_TIME * 60) . " >= " . time() . ")")))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_select", $sql_id);
}
$users_online = @mysql_result($sql_result, 0);
// ~~~~~ Free memory, close connection to MySQL server ~~~~~
dbDisconnect($sql_id, $sql_result);
// ~~~~~ Return number of users online (text/images) ~~~~~
if (COUNTER_MODE == 2)
{
$imghtml = "";
for ($i = 0; $i < @strlen($users_online); $i++)
{
$imghtml .= "<img src=\"" . COUNTER_IMG_SUBDIR . "/" . @substr($users_online, $i, 1) . ".gif\" border=\"0\" align=\"absmiddle\" title=\"Powered by phphits v" . SCRIPT_VERSION . "\">";
}
return $imghtml;
}
else
{
return $users_online;
}
}
// **********************************************************************
function phphitsShowHits($c_time)
{
// ~~~~~ Connect to MySQL server, activate database ~~~~~
if (!($sql_id = dbConnect()))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_connect", $sql_id);
}
// ~~~~~ Get number of hits from MySQL table ~~~~~
if ($c_time == 0)
{
if (!($sql_result = dbRunQuery($sql_id, "SELECT hits FROM " . SQL_TABLE_COUNTER . " WHERE (rowid=1) LIMIT 1")))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_select", $sql_id);
}
$sql_row = @mysql_fetch_array($sql_result);
$hits = $sql_row["hits"] + COUNTER_HITS_OFFSET;
}
else
{
$c_time = @abs($c_time * 3600);
if (!($sql_result = dbRunQuery($sql_id, "SELECT COUNT(*) FROM " . SQL_TABLE_LOG . " WHERE (tstamp + " . $c_time . " >= " . time() . ")")))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_select", $sql_id);
}
$hits = @mysql_result($sql_result, 0);
}
// ~~~~~ Free memory, close connection to MySQL server ~~~~~
dbDisconnect($sql_id, $sql_result);
// ~~~~~ Add 0's if necessary, return number of hits (text/images) ~~~~~
if (@strlen($hits) < COUNTER_DIGITS)
{
while ((@strlen($hits)) < COUNTER_DIGITS)
{
$hits = "0" . $hits;
}
}
if (COUNTER_MODE == 2)
{
$imghtml = "";
for ($i = 0; $i < @strlen($hits); $i++)
{
$imghtml .= "<img src=\"" . COUNTER_IMG_SUBDIR . "/" . @substr($hits, $i, 1) . ".gif\" border=\"0\" align=\"absmiddle\" title=\"Powered by phphits " . SCRIPT_VERSION . "\">";
}
return $imghtml;
}
else
{
return $hits;
}
}
// **********************************************************************
function phphitsResetCounter($mode)
{
// ~~~~~ Connect to MySQL server, activate database ~~~~~
if (!($sql_id = dbConnect()))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_connect", $sql_id);
}
// ~~~~~ Delete MySQL log table and/or reset counter table ~~~~~
if ($mode <> "3")
{
if (!($sql_result = dbRunQuery($sql_id, "DELETE FROM " . SQL_TABLE_LOG)))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_delete", $sql_id);
}
}
if($mode <> "2")
{
if (!($sql_result = dbRunQuery($sql_id, "UPDATE " . SQL_TABLE_COUNTER . " SET hits=0 WHERE rowid=1")))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_update", $sql_id);
}
}
// ~~~~~ Output some HTML code ~~~~~
echo "<hr noshade>";
echo "<font size=\"2\" face=\"" . LOG_FONT_FACE . "\"><b>The counter has been successfully reset.</b></font>";
echo "<hr noshade>";
// ~~~~~ Free memory, close connection to MySQL server ~~~~~
dbDisconnect($sql_id, $sql_result);
}
// **********************************************************************
function phphitsShowTop10($sql_field)
{
// ~~~~~ Connect to MySQL server, activate database ~~~~~
if (!($sql_id = dbConnect()))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_connect", $sql_id);
}
// ~~~~~ Get the 10 most frequent values from MySQL log table ~~~~~
if (!($sql_result = dbRunQuery($sql_id, "SELECT DISTINCT $sql_field, COUNT($sql_field) AS c FROM " . SQL_TABLE_LOG . " GROUP BY $sql_field ORDER BY c DESC LIMIT 10")))
{
if (SQL_SHOW_ERRORS) phphitsShowErrorMsg("mysql_select", $sql_id);
}
echo "\n<table width=\"600\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"#cccccc\">\n";
echo "\t<tr>\n";
echo "\t\t<td width=\"75\" bgcolor=\"#dddddd\">Hits</td>\n";
echo "\t\t<td width=\"525\" bgcolor=\"#dddddd\">" . @ucfirst($sql_field) . "</td>\n";
echo "\t</tr>\n";
while ($sql_row = @mysql_fetch_array($sql_result))
{
echo "\t<tr>\n";
echo "\t\t<td width=\"75\">" . $sql_row["c"] . "</td>\n";
if (($sql_field == "referrer") || ($sql_field == "page"))
{
$sql_row["$sql_field"] = "<a href=\"" . $sql_row["$sql_field"] . "\" target=\"_blank\">" . $sql_row["$sql_field"] . "</a>";
}
echo "\t\t<td width=\"525\">" . $sql_row["$sql_field"] . "</td>\n";
echo "\t</tr>\n";
}
echo "</table>\n";
// ~~~~~ Free memory, close connection to MySQL server ~~~~~
dbDisconnect($sql_id, $sql_result);
}
// **********************************************************************
function phphitsShowErrorMsg($err, $id)
{
// ~~~~~ Show HTML error message (depending on error type) ~~~~~
switch ($err)
{
case "mysql_connect":
$msg[1] = "Couldn't connect to MySQL server";
$msg[3] = "Check if the name of the MySQL server, user name & password specified in settings.inc.php are correct!";
break;
case "mysql_create_db":
$msg[1] = "Couldn't create MySQL database";
$msg[3] = "Check if the name of the MySQL database specified in settings.inc.php is correct!";
break;
case "mysql_create_table":
$msg[1] = "Couldn't create MySQL table";
$msg[3] = "Check if the name of the MySQL tables specified in settings.inc.php are correct!";
break;
case "mysql_select":
$msg[1] = "Couldn't query MySQL database";
$msg[3] = "Check if the name of the MySQL database specified in settings.inc.php is correct!";
break;
case "mysql_insert":
$msg[1] = "Couldn't insert new row into MySQL table";
$msg[3] = "Check if the name of the MySQL tables in settings.inc.php are correct!";
break;
case "mysql_update":
$msg[1] = "Couldn't update row in MySQL table";
$msg[3] = "Check if the name of the MySQL tables in settings.inc.php are correct!";
break;
case "mysql_delete":
$msg[1] = "Couldn't delete MySQL table rows.";
$msg[3] = "Check if the name of the MySQL tables in settings.inc.php is correct!";
break;
default:
$msg[1] = "MySQL error";
$msg[3] = "Check if all MySQL settings specified in settings.inc.php are correct!";
break;
}
if (@mysql_error($id) <> "")
{
$msg[2] = @mysql_error($id);
}
else
{
$msg[2] = "Unknown";
}
die("<hr><font face=\"Verdana, Arial, Helvetica, sans-serif\" color=\"#0033CC\" size=\"2\"><b>phphits v" . SCRIPT_VERSION . " - DATABASE ERROR:<br><br>" . $msg[1] . "</b><br>Reason: " . $msg[2] . "<p></p>" . $msg[3] . "</font><hr><br>");
}
?>