|
| Index | Recent Threads | Unanswered Threads | Who's Online | User List | Help |
|
|
| No member browsing this thread |
|
Thread Status: Active Total posts in this thread: 4
|
|
| Author |
|
|
Newbie USA Joined: Jul 23, 2008 Post Count: 40 Status: Offline |
Add this HTML to the bottom of the page you want to log: <iframe align="middle" frameborder="0" scrolling="no" height="1" width="1" src="../cgi/web_log/log_entry.pl"></iframe> Create a folder in your cgi-bin called "web_log" and put the following 2 scripts in it: "log_entry.pl" #!/usr/bin/perl # # SoftNet Website Log Entry # # # use LWP 5.64 print "Content-Type: text/html\n\n"; $browser = LWP::UserAgent->new; $url = "http://api.hostip.info/get_html.php?ip=" . $ENV{'REMOTE_ADDR'}; $response = $browser->get( $url ); $response->content_type eq 'text/html'; $content = $response->content; ($country,$city) = split(/City:/,$content); $city = "City: " . $city; open (LOG,">> log"); print LOG "<b>------------------------------------------------------------------------------------------------------------------------------------------------------------------</b>\n"; print LOG " | ",$city,"</b><br />\n"; print LOG "<b>Referer: ",$ENV{'HTTP_REFERER'}," | ",$country; print LOG "<br /><b>",scalar localtime()," | ",$ENV{'HTTP_USER_AGENT'}," | ",$ENV{'REMOTE_ADDR'},"</b><br />\n"; close (LOG); #----------------------------------------------------------------- "log.pl" #!/usr/bin/perl # # SoftNet Website Log # # # print "Content-Type: text/html\n\n"; print "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' /> <meta http-equiv='X-UA-Compatible' content='IE=7;FF=3;OtherUA=4' /> <title>SoftNet Website Log</title> <style type='text/css'> <!-- body,td,th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #FFFFFF; } body { background-color: #666666; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } .style3 { font-size: 50px; color: #0000FF; } .style5 { font-size: 9px; color: #FFFFFF; } --> </style> </head> <body> <div align='center' class='style3'> <b>SoftNet Web Log </b><hr /></div><div align='center' class='style5'><b>Current Log Date and Time: ",scalar localtime(),"</b><br /><b>------------------------------------------------------------------------------------------------------------------------------------------------------------------</b>\n"; open (LOG,"< log"); @log = reverse <LOG>; foreach (@log) { print $_; } close(LOG); print "</div> </body> </html>\n"; #------------------------------------------------------------------- To see your web log go to: http://www.yourdomain.com/cgi/web_log/log.pl To see a working version of this code go to: http://www.softnet-wd.com/cgi/web_log/log.pl It will provide you with some very basic information time, date, browser, remote IP address, country and city of the visitor easily and quickly for fun or for quick reference without a lot of code added to your page or java that slows the page load. You don't need to set up an account and login as with Google Analytics and isn't full of useless data that is confusing, just what type of browser, os, time, ip and demographics info... Have fun, enjoy. :) ![]() ---------------------------------------- Happy coding to you :) ---------------------------------------- [Edit 17 times, last edit by donnie1 at Sep 7, 2008 11:12:12 AM] |
||
|
|
Newbie USA Joined: Jul 23, 2008 Post Count: 40 Status: Offline |
I'm working on adding statistics to this log.... I will update this post when I finish with that Perl code. ---------------------------------------- Happy coding to you :) |
||
|
|
Newbie USA Joined: Jul 23, 2008 Post Count: 40 Status: Offline |
Here is the updated version with statistical information. A separate folder for logs is required, the path is this: [root] / [cgi-bin] / [web_log] / [logs] [web_log] is where all the pl files go, [logs] is left empty for the logs. remember to give all pl files the attribute 755. Copy and past into notepad the following Perl scripts: Add the iframe HTML code at the bottom of the body of all your web pages, adjust the path to your [root] / [cgi-bin] / [web_log] folder to your site, ie; ../cgi/web_log/log_entry.pl as follows: <iframe align="middle" frameborder="0" scrolling="no" height="1" width="1" src="../cgi/web_log/log_entry.pl"></iframe> ------------------------------------------------------------------------------- "log.pl" #!/usr/bin/perl # # SoftNet Website Log # # # do 'stats.pl'; print "Content-Type: text/html\n\n"; print "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'> <html xmlns='http://www.w3.org/1999/xhtml'> <head> <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' /> <meta http-equiv='X-UA-Compatible' content='IE=7;FF=3;OtherUA=4' /> <title>SoftNet Website Log</title> <style type='text/css'> <!-- body,td,th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10px; color: #FFFFFF; } body { background-color: #666666; margin-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; } .style3 { font-size: 50px; color: #0000FF; } .style5 { font-size: 9px; color: #FFFFFF; } --> </style> </head> <body> <div align='center' class='style3'> <b>SoftNet Web Log </b><hr /></div><div align='center' class='style5'><b>Current Log Date and Time: ",scalar localtime(),"</b><br /><b>------------------------------------------------------------------------------------------------------------------------------------------------------------------</b><br />\n"; print "<b>Total Website Hits to Date: ",$t_hits," | Unique Website Hits to Date: ",$u_hits,"<b><br />\n"; print "<b>------------------------------------------------------------------------------------------------------------------------------------------------------------------</b><br />\n"; print "<b>- List of Countries by Percentage -</b><br />\n"; foreach (@countryx){ print "<b>",$_,"</b><br />\n"; } print "<b>------------------------------------------------------------------------------------------------------------------------------------------------------------------</b><br />\n"; print "<b>- List of Cities by Percentage -</b><br />\n"; foreach (@cityx){ print "<b>",$_,"</b><br />\n"; } print "<b>------------------------------------------------------------------------------------------------------------------------------------------------------------------</b><br />\n"; print "<b>- List of Referers by Percentage -</b><br />\n"; foreach (@refererx){ print "<b>",$_,"</b><br />\n"; } print "<b>------------------------------------------------------------------------------------------------------------------------------------------------------------------</b><br />\n"; print "<b>- List of Agents by Percentage -</b><br />\n"; foreach (@agentx){ print "<b>",$_,"</b><br />\n"; } print "<b>------------------------------------------------------------------------------------------------------------------------------------------------------------------</b><br />\n"; print "<b>- Ascending Log Data -</b><br />\n"; print "<b>------------------------------------------------------------------------------------------------------------------------------------------------------------------</b>\n"; open (LOG,"< logs/log"); @log = reverse <LOG>; foreach (@log) { print $_; } close(LOG); print "<br /><b>Web Log Copyright � 2008 by SoftNet</b></div> </body> </html>\n"; #---------------------------------------------------------------------------- "log_entry.pl" #!/usr/bin/perl # # SoftNet Website Log Entry # # # use LWP 5.64 print "Content-Type: text/html\n\n"; $remote_addr = $ENV{'REMOTE_ADDR'}; chomp($remote_addr); if ($remote_addr eq "" || $remote_addr eq " "){$remote_addr = "(Unknown IP Address)";} $http_user_agent = $ENV{'HTTP_USER_AGENT'}; chomp($http_user_agent); if ($http_user_agent eq "" || $http_user_agent eq " "){$http_user_agent = "(Unknown User Agent)";} $http_referer = $ENV{'HTTP_REFERER'}; chomp($http_referer); if ($http_referer eq "" || $http_referer eq " "){$http_referer = "(Unknown Referer)";} $local_time = scalar localtime(); chomp($local_time); if ($local_time eq "" || $local_time eq " "){$local_time = "(Unknown Log Time)";} $browser = LWP::UserAgent->new; $url = "http://api.hostip.info/get_html.php?ip=" . $remote_addr; $response = $browser->get( $url ); $response->content_type eq 'text/html'; $content = $response->content; if ($content eq "" || $content eq " "){$content = "Country: (Geo Data Base Error) City: (No Response From Geo Data Base)";} ($country,$city) = split(/City:/,$content); chop($country); $city = "City: " . $city; open (LOG,">> logs/log"); print LOG "<b>--------------------------------------------------------------------------------------------------------------------------------------------------------- ---------</b>\n"; print LOG "<b>Referer: ",$http_referer," | ",$country," | ",$city,"</b><br />\n"; print LOG "<br /><b>",$local_time," | ",$http_user_agent," | ",$remote_addr,"</b><br />\n"; close (LOG); ($null,$cty) = split(/City: /,$city); ($null,$cntry) = split(/Country: /,$country); open (IP,">> logs/ip"); print IP $remote_addr,"\n"; close (IP); open (AGENT,">> logs/agent"); print AGENT $http_user_agent,"\n"; close (AGENT); open (COUNTRY,">> logs/country"); print COUNTRY $cntry,"\n"; close (COUNTRY); open (CITY,">> logs/city"); print CITY $cty,"\n"; close (CITY); open (REFERER,">> logs/referer"); print REFERER $http_referer,"\n"; close (REFERER); #------------------------------------------------------------------------------ "stats.pl" #!/usr/bin/perl # # SoftNet Website Log Statistics # # # open (IP,"< logs/ip"); @ip = <IP>; close (IP); @sample = (); $org = 0; $u_hits = 0; $pos = 0; foreach (@ip){ $ipx = $_; $t_hits++; $org = 0; foreach (@sample){ if ($ipx eq $_){ $org = 1; } } foreach (@ip){ if (($ipx eq $_) && ($org eq 0)){ $org = 1; @sample [$pos] = $ipx; $pos++; $u_hits++; } } } open (AGENT,"< logs/agent"); @sub = <AGENT>; close (AGENT); @sample = (); @subx = (); &get_data; @agentx = @subx; open (COUNTRY,"< logs/country"); @sub = <COUNTRY>; close (COUNTRY); @sample = (); @subx = (); &get_data; @countryx = @subx; open (CITY,"< logs/city"); @sub = <CITY>; close (CITY); @sample = (); @subx = (); &get_data; @cityx = @subx; open (REFERER,"< logs/referer"); @sub = <REFERER>; close (REFERER); @sample = (); @subx = (); &get_data; @refererx = @subx; sub get_data{ $posxx = 0; $posx = 0; $cnt = 0; foreach (@sub){ $t_sub = 0; $u_sub = 0; $subx = $_; $subxx = $_; chop($subxx); $org = 0; $cnt++; $xorg = 0; foreach (@sample){ if ($subx eq $_){ $org = 1; $xorg = 1; } } foreach (@sub){ $t_sub++; if (($subx eq $_) && ($org eq 0)){ @subx [$posxx] = $subxx; @sample [$posxx] = $subx; $u_sub++; $posxx++; $org = 1; $add = 1; } if (($subx eq $_) && ($org eq 1)){ $u_sub++; $add = 1; } } if ($posxx > 0){$posx = $posxx -1;} if (($add eq 1) && ($xorg eq 0)){ $cal = ((($u_sub -1) / $t_sub) * 100); ($cal,$null) = split(/\./,$cal); $sort = $posx + $cal; @subx [$posx] = @subx [$posx] . " = " . $cal . "%"; @sort [$sort] = @subx [$posx]; $add = 0; } } @subx = (); $asc = -1; foreach (@sort){ if ($_ ne ""){ $asc++; @subx [$asc] = $_; } } @sort = (); @subx = reverse @subx; } #------------------------------------------------------------------------------ This script is up and running on my site, you can see it at: http://www.softnet-wd.com/cgi/web_log/log.pl If you have any questions, need help or have a suggestion on something to make it better please let me know. Have fun, enjoy! :) ---------------------------------------- Happy coding to you :) ---------------------------------------- [Edit 13 times, last edit by donnie1 at Sep 9, 2008 1:43:42 PM] |
||
|
|
Newbie USA Joined: Jul 23, 2008 Post Count: 40 Status: Offline |
Please leave a message when you visit this post, let me know if you like the script.... or just say hi! :)---------------------------------------- Happy coding to you :) |
||
|
|
|
|
|
Current timezone is GMT Mar 21, 2010 11:02:37 PM |