We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

How to create analytical chart

I need to create chart for log

Database fields are,

*** host
* pageurl
* VisitPage
* VisitorIP
* VisitDate
* VisitorTimeZone
* VisitTime
* browser
* operatingsystem
* referer**

I need chart for Toatl Visits, Uniquie Visits, Impressions, Online Users, Pageviews,
%New Visits, % Uniquie Visits, %New Visitor, %Returning Visitor

There is problem with VisitTime and VisitorTimeZone it is not showing accurate values

Here is log.php

<?php
$page_name = $_SERVER['PHP_SELF']; // PAGE NAME 
$parse_page_name = basename ($page_name); // PARSE THE EXACT PAGE NAME
// Get the URL
$host = $_SERVER['SERVER_NAME'];
// Get the IP Address
$ipAddress =$_SERVER['REMOTE_ADDR'];
//format the URL
//$visitURL = $url.$scriptName;
$today = date("j, F, Y");  
$tmzone=date_default_timezone_get();
$now=strftime("%I:%M:%S");
$stz=gmstrftime("%Z");
$visitortimezone=("$tmzone, ($stz)");
function getBrowser() 
{ 
    $u_agent = $_SERVER['HTTP_USER_AGENT']; 
    $bname = 'Unknown';
    $platform = 'Unknown';
    $version= "";
    //First get the platform?
    if (preg_match('/linux/i', $u_agent)) {
        $platform = 'linux';
    }
    elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
        $platform = 'mac';
    }
    elseif (preg_match('/windows|win32/i', $u_agent)) {
        $platform = 'windows';
    }
    // Next get the name of the useragent yes seperately and for good reason
    if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent)) 
    { 
        $bname = 'Internet Explorer'; 
        $ub = "MSIE"; 
    } 
    elseif(preg_match('/Firefox/i',$u_agent)) 
    { 
        $bname = 'Mozilla Firefox'; 
        $ub = "Firefox"; 
    } 
    elseif(preg_match('/Chrome/i',$u_agent)) 
    { 
        $bname = 'Google Chrome'; 
        $ub = "Chrome"; 
    } 
    elseif(preg_match('/Safari/i',$u_agent)) 
    { 
        $bname = 'Apple Safari'; 
        $ub = "Safari"; 
    } 
    elseif(preg_match('/Opera/i',$u_agent)) 
    { 
        $bname = 'Opera'; 
        $ub = "Opera"; 
    } 
    elseif(preg_match('/Netscape/i',$u_agent)) 
    { 
        $bname = 'Netscape'; 
        $ub = "Netscape"; 
    } 
    // finally get the correct version number
    $known = array('Version', $ub, 'other');
    $pattern = '#(?<browser>' . join('|', $known) .
    ')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
    if (!preg_match_all($pattern, $u_agent, $matches)) {
        // we have no matching number just continue
    }
    // see how many we have
    $i = count($matches['browser']);
    if ($i != 1) {
        //we will have two since we are not using 'other' argument yet
        //see if version is before or after the name
        if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
            $version= $matches['version'][0];
        }
        else {
            $version= $matches['version'][1];
        }
    }
    else {
        $version= $matches['version'][0];
    }
    // check if we have a number
    if ($version==null || $version=="") {$version="?";}
    return array(
        'userAgent' => $u_agent,
        'name'      => $bname,
        'version'   => $version,
        'platform'  => $platform,
        'pattern'    => $pattern
    );
}
$ua=getBrowser();
$browser="$ua[name] $ua[version]";
$os="$ua[platform]";
$referer = $_SERVER['HTTP_REFERER'];

$sql="INSERT INTO visitslog (host,pageurl,VisitPage,VisitorIP,VisitDate,VisitorTimeZone,VisitTime,browser,operatingsystem,referer)       VALUES('$host','$page_name','$parse_page_name','$ipAddress','$today','$visitortimezone','$now','$browser','$os','$referer')";
$result=mysql_query($sql);
?>

Please help

5
Contributors
15
Replies
1 Week
Discussion Span
3 Months Ago
Last Updated
16
Views
vizz
Posting Whiz
399 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 5

Where do you do any calculations for the chart especially for the values in question? If you want to know what is good library for drawing charts I highly recommend jQplot.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

thanks

I need help for calculations too

vizz
Posting Whiz
399 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 5

What exactly would you like to show for VisitTime and VisitorTimeZone? I can guess the timezones can be counted something like:

$tzQuery = 'SELECT VisitorTimeZone, COUNT(*) AS tz_count 
            FROM visitslog GROUP BY VisitorTimeZone';
broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

For an old project, I used this
JPowered

Which does the graph work, all you have to do is echo some information into the script, it does all of the maths, and it works really well and easily

mattster
Junior Poster
126 posts since Nov 2012
Reputation Points: 9
Solved Threads: 8
Skill Endorsements: 0

$visitortimezone=("$tmzone, ($stz)"); and $now=strftime("%I:%M:%S");
is not working well

vizz
Posting Whiz
399 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 5

You are not saying much :-). Can you please explain what and how is not working well (what you expect v.s. what comes out, error messages).

$visitortimezone=("$tmzone, ($stz)");

Seems like a function name is missing here? What you intended to do?

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

visitortimezone give Europe/Berlin, (India Standard Time) for localhost

VisitTime give 05:29:37 for 10 AM IST for localhost

I need visitors exact time related info.

Also please help to find, Uniquie Visits, Impressions, Online Users, Pageviews,
%New Visits, % Uniquie Visits, %New Visitor, %Returning Visitor

vizz
Posting Whiz
399 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 5

visitortimezone give Europe/Berlin, (India Standard Time) for localhost
VisitTime give 05:29:37 for 10 AM IST for localhost

Will this link help?

http://stackoverflow.com/questions/3905193/convert-time-and-date-from-one-time-zone-to-another-in-php

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

I used and liked very much this JS chart API: http://www.highcharts.com/

Hope it helps.

AleMonteiro
Master Poster
752 posts since Aug 2010
Reputation Points: 129
Solved Threads: 140
Skill Endorsements: 23

Just a note on the use of DateTime - following on from broj1's link (nice one broj +1). IMO, it's the killer object for dealing with almost every date issue. However, to my horror, my beautifully crafted DateTime extension class failed to work as expected because I was using a VC6 php build as opposed to the VC9. So, lesson learned - if you want to use DateTime (and you should) - do check which version and build of php you're running - it prompted me to update php.

I used and liked very much this JS chart API: http://www.highcharts.com/

The high* JS series of scripts are fantastic. A big me too, on that (+1).

diafol
Keep Smiling
Moderator
10,613 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57

my beautifully crafted DateTime extension class failed to work as expected because I was using a VC6 php build as opposed to the VC9

Took me some time to figure out what VC stands for :-) I have never used VS and rarely use Windows these days. Thanks for sharing this info.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

Thanks for sharing this info.

No problem. This is relatively simple to sort out on your own PC, but ensuring latest php version on your shared hosting account, may be a different matter! Could all end in tears, especially if you're developing a solution for a client, paying or otherwise! But as mentioned, this particular problem seems only to affect Windows.

diafol
Keep Smiling
Moderator
10,613 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57

Need help to detect
Uniquie Visits, Impressions, Online Users, Pageviews,Returning Visitor

vizz
Posting Whiz
399 posts since Dec 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 5

Just a few ideas. Can't say they are 100% OK, since I do not know much about your app. Do some tests.

// Unique visits by host
SELECT COUNT(*) AS hostcount, host FROM log GROUP BY host

// Unique visits by VisitorIP
SELECT COUNT(*) AS visitoripcount, VisitorIP FROM log GROUP BY VisitorIP 

// Pageviews
SELECT COUNT(*) AS pagevievcount, VisitPage FROM log GROUP BY VisitPage

// Returning visitors by VisitorIP
SELECT COUNT(*) AS returningcount, VisitorIP**Bold Text Here**  FROM log GROUP BY VisitorIP HAVING COUNT(*) > 1

Impressions? What is this?

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

For online users you have to do some guessing. You do not log the logout time so you can't compare it with login time. And this method is not reliable since the user might just close the browser. You can also check sessions or write a fancy javascript such as this.

broj1
Nearly a Posting Virtuoso
1,211 posts since Jan 2011
Reputation Points: 167
Solved Threads: 164
Skill Endorsements: 13

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.1155 seconds using 2.78MB