offline
- Pridružio: 26 Avg 2008
- Poruke: 100
|
Zdravo svima, da li neko može da mi pomogne oko php statistike za brojač poseta na sajtu?
Skripta je radila na Php 5. Ali moram da prebacim na php 7. Prebacio sve na "mysqli" kao što piše na php.net/manual/en/ref.mysql.php. Ali zbog nečega i dalje ne radi na php 7. Da li neko možda zna u čemu je problem ?
connect.php
<?php
/* Database config */
$db_host = 'localhost';
$db_user = 'moj_user';
$db_pass = 'moj_password';
$db_database = 'moj_user_naziv_baze';
/* End config */
$link = @mysqli_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');
mysqli_set_charset('utf8');
mysqli_select_db($db_database,$link);
?>
fuctions.php
<?php
/* Helper functions: */
function get_tag($tag,$xml)
{
preg_match_all('/<'.$tag.'>(.*)<\/'.$tag.'>$/imU',$xml,$match);
return $match[1];
}
function is_bot()
{
/* This function will check whether the visitor is a search engine robot */
$botlist = array("Teoma", "alexa", "froogle", "Gigabot", "inktomi",
"looksmart", "URL_Spider_SQL", "Firefly", "NationalDirectory",
"Ask Jeeves", "TECNOSEEK", "InfoSeek", "WebFindBot", "girafabot",
"crawler", "www.galaxy.com", "Googlebot", "Scooter", "Slurp",
"msnbot", "appie", "FAST", "WebBug", "Spade", "ZyBorg", "rabaz",
"Baiduspider", "Feedfetcher-Google", "TechnoratiSnoop", "Rankivabot",
"Mediapartners-Google", "Sogou web spider", "WebAlta Crawler","TweetmemeBot",
"Butterfly","Twitturls","Me.dium","Twiceler");
foreach($botlist as $bot)
{
if(strpos($_SERVER['HTTP_USER_AGENT'],$bot)!==false)
return true; // Is a bot
}
return false; // Not a bot
}
?>
geodata.php
<?php
require "connect.php";
require "functions.php";
// We don't want web bots accessing this page:
if(is_bot()) die();
// Selecting the top 15 countries with the most visitors:
$result = mysqli_query(" SELECT countryCode,country, COUNT(*) AS total
FROM tz_who_is_online
GROUP BY countryCode
ORDER BY total DESC
LIMIT 15");
while($row=mysqli_fetch_assoc($result))
{
echo '
<div class="geoRow">
<div class="flag"><img src="who-is-online/img/famfamfam-countryflags/'.strtolower($row['countryCode']).'.gif" width="16" height="11" /></div>
<div class="country" title="'.htmlspecialchars($row['country']).'">'.$row['country'].'</div>
<div class="people">'.$row['total'].'</div>
</div>
';
}
?>
online.php
<?php
require "connect.php";
require "functions.php";
// We don't want web bots scewing our stats:
if(is_bot()) die();
$stringIp = $_SERVER['REMOTE_ADDR'];
$intIp = ip2long($stringIp);
// Checking wheter the visitor is already marked as being online:
$inDB = mysqli_query("SELECT 1 FROM tz_who_is_online WHERE ip=".$intIp);
if(!mysqli_num_rows($inDB))
{
// This user is not in the database, so we must fetch
// the geoip data and insert it into the online table:
if($_COOKIE['geoData'])
{
// A "geoData" cookie has been previously set by the script, so we will use it
// Always escape any user input, including cookies:
list($city,$countryName,$countryAbbrev) = explode('|',mysqli_real_escape_string(strip_tags($_COOKIE['geoData'])));
}
else
{
// Making an API call to Hostip:
$xml = file_get_contents('http://api.hostip.info/?ip='.$stringIp);
$city = get_tag('gml:name',$xml);
$city = $city[1];
$countryName = get_tag('countryName',$xml);
$countryName = $countryName[0];
$countryAbbrev = get_tag('countryAbbrev',$xml);
$countryAbbrev = $countryAbbrev[0];
// Setting a cookie with the data, which is set to expire in a month:
setcookie('geoData',$city.'|'.$countryName.'|'.$countryAbbrev, time()+60*60*24*30,'/');
}
$countryName = str_replace('(Unknown Country?)','UNKNOWN',$countryName);
// In case the Hostip API fails:
if (!$countryName)
{
$countryName='UNKNOWN';
$countryAbbrev='XX';
$city='(Unknown City?)';
}
mysqli_query(" INSERT INTO tz_who_is_online (ip,city,country,countrycode)
VALUES(".$intIp.",'".$city."','".$countryName."','".$countryAbbrev."')");
}
else
{
// If the visitor is already online, just update the dt value of the row:
mysqli_query("UPDATE tz_who_is_online SET dt=NOW() WHERE ip=".$intIp);
}
// Removing entries not updated in the last 10 minutes:
mysqli_query("DELETE FROM tz_who_is_online WHERE dt<SUBTIME(NOW(),'0 0:10:0')");
// Counting all the online visitors:
list($totalOnline) = mysqli_fetch_array(mysqli_query("SELECT COUNT(*) FROM tz_who_is_online"));
// Outputting the number as plain text:
echo $totalOnline;
?>
|