{"id":1518,"date":"2018-01-19T19:22:56","date_gmt":"2018-01-19T19:22:56","guid":{"rendered":"http:\/\/goofy-trucks.flywheelsites.com\/revisited-logging-with-php\/"},"modified":"2018-01-19T19:24:51","modified_gmt":"2018-01-19T19:24:51","slug":"revisited-logging-with-php","status":"publish","type":"post","link":"https:\/\/phpbuilder.com\/revisited-logging-with-php\/","title":{"rendered":"Revisited: Logging With PHP"},"content":{"rendered":"<div class=\"phpbuilder-content\">\n<div class=\"phpbuilder-meta\">\n<div class=\"\">By Tim Perdue<\/div>\n<div class=\"\">on December 10, 2000<\/div>\n<\/p><\/div>\n<div id=\"overflow-content\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/phpbuilder.com\/wp-content\/uploads\/2018\/01\/tim2.jpg\" class=\"articleAuthorImg\" alt=\"picture of Tim Perdue\" height=\"90\" width=\"100\" align=\"left\"\/><\/p>\n<div class=\"articlePara\">\nFiguring out where your hits are coming from and which<br \/>\npages are being viewed is not too difficult if you use a<br \/>\ngood log analyzer like Analog or something similar.<\/div>\n<div class=\"articlePara\">\nBut if you want to pull up reports on the fly at any time,<br \/>\nyou need to take a different route.<\/div>\n<div class=\"articlePara\">\nFor about six months, I was importing my Apache logs into<br \/>\nan SQL database and then running ad-hoc queries against that.<\/div>\n<div class=\"articlePara\">\nUnfortunately, that requires me to go out and manually grab<br \/>\nthose log files, tweak the format a bit, then import. I wanted<br \/>\nsomething better &#8211; something that was continually updated,<br \/>\ngave me information on what content was being viewed,<br \/>\nbrowser and platforms stats, and trends over time.<\/div>\n<div class=\"articlePara\">\nThe solution I came up with in my <a href=\"tim19990130.html\" target=\"_blank\">original version<\/a> of this<br \/>\narticle has served me well for a couple years now. I enhanced it<br \/>\nsomewhat when we built SourceForge and all logging and tracking<br \/>\nfor the entire SourceForge.net web site pipes through this<br \/>\nsystem, including page views on the main site and page views<br \/>\nfor each of the 12,000 projects that use the site.<\/div>\n<div class=\"articlePara\">\nBasically, what I do is add a row to a table in a database for<br \/>\neach action I want to log (page views in this example, but you can log<br \/>\nbanner add views, clicks, click-ins from other sites, etc).<\/div>\n<div class=\"articlePara\">\nHere is the table structure I&#8217;ve been using on SourceForge:<\/div>\n<div class=\"example\">\n<pre>\ncreate table activity_log (\n  day integer DEFAULT '0' NOT NULL,\n  hour integer DEFAULT '0' NOT NULL,\n  group_id integer DEFAULT '0' NOT NULL,\n  browser varchar(8) DEFAULT 'OTHER' NOT NULL,\n  ver float(10) DEFAULT '0.00' NOT NULL,\n  platform varchar(8) DEFAULT 'OTHER' NOT NULL,\n  time integer DEFAULT '0' NOT NULL,\n  page text,\n  type integer DEFAULT '0' NOT NULL\n);\n<\/pre>\n<\/div>\n<div class=\"articlePara\">\nThe <i>group_id<\/i> column can be used if you have multiple web sites<br \/>\nyou are trying to track. Just assign a different group_id to each site<br \/>\nand pass it in the URL (shown below).<\/div>\n<div class=\"articlePara\">\n<i>type<\/i> is unused in these<br \/>\nexamples, but you can use it to track different types of actions, like<br \/>\nad clicks, clickins from other sites, etc.<\/div>\n<div class=\"articlePara\">\n<i>browser, ver, platform<\/i> are all obtained from the <b>$HTTP_USER_AGENT<\/b><br \/>\nvariable which is passed by your browser to the web server. I have a<br \/>\nbrowser detection library which we call to fill in this info. The code for<br \/>\nthat is available elsewhere in this article.<\/div>\n<div class=\"articlePara\">\n<i>page<\/i> is any arbitrary information that you want to log &#8211; I<br \/>\ngenerally log <b>$PHP_SELF<\/b>.<\/div>\n<\/div>\n<p><\/p>\n<div style=\"float: left; padding:15px; color:#17AAF3\">\n<div style=\"background-color:#B6E5FC; font-size:16px; margin-top:1px; padding:1px 4px 1px 4px; color:#000; font-style:bold; float:left;\">1<\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"tim200012114658.html?page=2\">2<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"tim200012119ba9.html?page=3\">3<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"tim20001211fdb0.html?page=4\">4<\/a> <\/div>\n<div style=\"float:left; font-size:16px; color:#FF7A22; padding:2px 2px 2px 2px; \">| <\/div>\n<div style=\"float:left; padding:2px 4px 2px 4px;\"><a class=\"pageNumber\" href=\"tim20001211af4d.html?page=5\">5<\/a> <\/div>\n<div style=\"float:left; padding:2px;\"><a class=\"paginationPageLink\" href=\"tim200012114658.html?page=2\">Next Page \u00bb<\/a><\/div>\n<\/div>\n<p> Download: <a href=\"https:\/\/phpbuilder.com\/wp-content\/uploads\/2018\/01\/tim20001211.zip\">tim20001211.zip<\/a>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>By Tim Perdue on December 10, 2000 Figuring out where your hits are coming from and which pages are being viewed is not too difficult if you use a good log analyzer like Analog or something similar. But if you want to pull up reports on the fly at any&#8230; <a href=\"https:\/\/phpbuilder.com\/revisited-logging-with-php\/\" class=\"readmore\"><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1518","post","type-post","status-publish","format-standard","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/comments?post=1518"}],"version-history":[{"count":2,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1518\/revisions"}],"predecessor-version":[{"id":2411,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/posts\/1518\/revisions\/2411"}],"wp:attachment":[{"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/media?parent=1518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/categories?post=1518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/phpbuilder.com\/wp-json\/wp\/v2\/tags?post=1518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}