{"id":166,"date":"2010-10-13T06:17:31","date_gmt":"2010-10-13T14:17:31","guid":{"rendered":"https:\/\/www.bhavyatechnologies.com\/blog\/?p=166"},"modified":"2010-10-19T06:02:18","modified_gmt":"2010-10-19T14:02:18","slug":"making-usage-statistics-in-php-storing-the-data","status":"publish","type":"post","link":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/","title":{"rendered":"Making Usage Statistics in PHP \u2013 Storing the Data"},"content":{"rendered":"<p>Let&#8217;s start with the database part. We&#8217;ll need only one table that stores each click (page impression) of each visitor. The name of the table will be &#8220;hits&#8221;. What should we store here?<\/p>\n<p>1. The hostname is very important to identify the client. <a href=\"http:\/\/www.devarticles.com\/#\" target=\"_blank\">PHP<img decoding=\"async\" src=\"http:\/\/images.intellitxt.com\/ast\/adTypes\/mag-glass_10x10.gif\" alt=\"\" \/><\/a> gives us the IP address that I like to convert to hostname with gethostbyaddr(). I think it&#8217;s better to see a string.<br \/>\n2. The time of visit can be stored easily by using the NOW() function of MySQL.<br \/>\n3. The visited page on your site should be stored. In most cases, you should store the URL of the visited page and the HTML title in two separated fields, eg. URL and Title fields, so that you&#8217;ll be able to see your most visited sites simply by looking through the list of their titles.<\/p>\n<p>Now we&#8217;re going to write the piece of code that will save the hit. It will be called at the beginning of the program. To save the requested URL in the database you can use $_SERVER[&#8216;PHP_SELF&#8217;] that gives you the URL without the domain name or $_SERVER[&#8216;QUERY_STRING&#8217;] that gives you the parameters in the URL after the question mark.<\/p>\n<p><strong>Warning:<\/strong> $_SERVER[&#8216;PHP_SELF&#8217;] doesn&#8217;t contain the query string, only the path related to the <a href=\"http:\/\/www.devarticles.com\/#\" target=\"_blank\">server<img decoding=\"async\" src=\"http:\/\/images.intellitxt.com\/ast\/adTypes\/mag-glass_10x10.gif\" alt=\"\" \/><\/a> root and the filename. For instance if you call http:\/\/www.mydomain.com\/folder1\/personal\/main.php?id=56 then PHP_SELF is \/folder1\/personal\/main.php.<\/p>\n<p>I prefer $_SERVER[&#8216;QUERY_STRING&#8217;].\u00a0 This can be especially useful if you use only one PHP to all functions, for example, you call &#8220;\/index.php?op=forum&amp;topicid=768&#8221; if you&#8217;d like to show a given forum topic or for showing articles \/index.php?op=articles&amp;id=25. Using QUERY_STRING, You will get &#8220;op=articles&amp;id=25&#8221; that will be enough to identify the requested page.<\/p>\n<p>Source: www.devarticles.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s start with the database part. We&#8217;ll need only one table that stores each click (page impression) of each visitor. The name of the table will be &#8220;hits&#8221;. What should we store here? 1. The hostname is very important to identify the client. PHP gives us the IP address that I like to convert to &hellip; <a href=\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Making Usage Statistics in PHP \u2013 Storing the Data<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-166","post","type-post","status-publish","format-standard","hentry","category-php"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Making Usage Statistics in PHP \u2013 Storing the Data - Bhavya Technologies - Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Making Usage Statistics in PHP \u2013 Storing the Data - Bhavya Technologies - Blog\" \/>\n<meta property=\"og:description\" content=\"Let&#8217;s start with the database part. We&#8217;ll need only one table that stores each click (page impression) of each visitor. The name of the table will be &#8220;hits&#8221;. What should we store here? 1. The hostname is very important to identify the client. PHP gives us the IP address that I like to convert to &hellip; Continue reading Making Usage Statistics in PHP \u2013 Storing the Data\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/\" \/>\n<meta property=\"og:site_name\" content=\"Bhavya Technologies - Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/BhavyaWebTech\/\" \/>\n<meta property=\"article:published_time\" content=\"2010-10-13T14:17:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2010-10-19T14:02:18+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/images.intellitxt.com\/ast\/adTypes\/mag-glass_10x10.gif\" \/>\n<meta name=\"author\" content=\"Bhavya Technologies\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bhavyatech\" \/>\n<meta name=\"twitter:site\" content=\"@bhavyatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bhavya Technologies\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/\"},\"author\":{\"name\":\"Bhavya Technologies\",\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/#\/schema\/person\/a8b972526a82dee1d674d1fcb5124895\"},\"headline\":\"Making Usage Statistics in PHP \u2013 Storing the Data\",\"datePublished\":\"2010-10-13T14:17:31+00:00\",\"dateModified\":\"2010-10-19T14:02:18+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/\"},\"wordCount\":325,\"publisher\":{\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/images.intellitxt.com\/ast\/adTypes\/mag-glass_10x10.gif\",\"articleSection\":[\"PHP\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/\",\"url\":\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/\",\"name\":\"Making Usage Statistics in PHP \u2013 Storing the Data - Bhavya Technologies - Blog\",\"isPartOf\":{\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#primaryimage\"},\"thumbnailUrl\":\"http:\/\/images.intellitxt.com\/ast\/adTypes\/mag-glass_10x10.gif\",\"datePublished\":\"2010-10-13T14:17:31+00:00\",\"dateModified\":\"2010-10-19T14:02:18+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#primaryimage\",\"url\":\"http:\/\/images.intellitxt.com\/ast\/adTypes\/mag-glass_10x10.gif\",\"contentUrl\":\"http:\/\/images.intellitxt.com\/ast\/adTypes\/mag-glass_10x10.gif\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.bhavyatechnologies.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Making Usage Statistics in PHP \u2013 Storing the Data\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/#website\",\"url\":\"https:\/\/www.bhavyatechnologies.com\/blog\/\",\"name\":\"Bhavya Technologies - Blog\",\"description\":\"\u00a0Digital Marketing, Website design &amp; development company in Hyderabad, India\",\"publisher\":{\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.bhavyatechnologies.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/#organization\",\"name\":\"Bhavya Web Technologies\",\"url\":\"https:\/\/www.bhavyatechnologies.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.bhavyatechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/cropped-NewLogo.png\",\"contentUrl\":\"https:\/\/www.bhavyatechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/cropped-NewLogo.png\",\"width\":248,\"height\":100,\"caption\":\"Bhavya Web Technologies\"},\"image\":{\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/BhavyaWebTech\/\",\"https:\/\/x.com\/bhavyatech\",\"http:\/\/www.linkedin.com\/company\/bhavya-technologies\/\",\"http:\/\/www.youtube.com\/user\/bhavyatechnologies\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/#\/schema\/person\/a8b972526a82dee1d674d1fcb5124895\",\"name\":\"Bhavya Technologies\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.bhavyatechnologies.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/fe762d42f67c5102549b2df80f35f4328850bd6b77a18d11070f369c3854d473?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/fe762d42f67c5102549b2df80f35f4328850bd6b77a18d11070f369c3854d473?s=96&d=mm&r=g\",\"caption\":\"Bhavya Technologies\"},\"description\":\"We are team of young, energetic and dynamic members, focused on providing high quality website designing, website development and Internet Marketing services. With a team of such Bhavya member we always try and deliver high quality of project, exceeding client\u2019s expectation.\",\"sameAs\":[\"http:\/\/www.bhavyatechnologies.com\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Making Usage Statistics in PHP \u2013 Storing the Data - Bhavya Technologies - Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/","og_locale":"en_US","og_type":"article","og_title":"Making Usage Statistics in PHP \u2013 Storing the Data - Bhavya Technologies - Blog","og_description":"Let&#8217;s start with the database part. We&#8217;ll need only one table that stores each click (page impression) of each visitor. The name of the table will be &#8220;hits&#8221;. What should we store here? 1. The hostname is very important to identify the client. PHP gives us the IP address that I like to convert to &hellip; Continue reading Making Usage Statistics in PHP \u2013 Storing the Data","og_url":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/","og_site_name":"Bhavya Technologies - Blog","article_publisher":"https:\/\/www.facebook.com\/BhavyaWebTech\/","article_published_time":"2010-10-13T14:17:31+00:00","article_modified_time":"2010-10-19T14:02:18+00:00","og_image":[{"url":"http:\/\/images.intellitxt.com\/ast\/adTypes\/mag-glass_10x10.gif","type":"","width":"","height":""}],"author":"Bhavya Technologies","twitter_card":"summary_large_image","twitter_creator":"@bhavyatech","twitter_site":"@bhavyatech","twitter_misc":{"Written by":"Bhavya Technologies","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#article","isPartOf":{"@id":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/"},"author":{"name":"Bhavya Technologies","@id":"https:\/\/www.bhavyatechnologies.com\/blog\/#\/schema\/person\/a8b972526a82dee1d674d1fcb5124895"},"headline":"Making Usage Statistics in PHP \u2013 Storing the Data","datePublished":"2010-10-13T14:17:31+00:00","dateModified":"2010-10-19T14:02:18+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/"},"wordCount":325,"publisher":{"@id":"https:\/\/www.bhavyatechnologies.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#primaryimage"},"thumbnailUrl":"http:\/\/images.intellitxt.com\/ast\/adTypes\/mag-glass_10x10.gif","articleSection":["PHP"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/","url":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/","name":"Making Usage Statistics in PHP \u2013 Storing the Data - Bhavya Technologies - Blog","isPartOf":{"@id":"https:\/\/www.bhavyatechnologies.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#primaryimage"},"image":{"@id":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#primaryimage"},"thumbnailUrl":"http:\/\/images.intellitxt.com\/ast\/adTypes\/mag-glass_10x10.gif","datePublished":"2010-10-13T14:17:31+00:00","dateModified":"2010-10-19T14:02:18+00:00","breadcrumb":{"@id":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#primaryimage","url":"http:\/\/images.intellitxt.com\/ast\/adTypes\/mag-glass_10x10.gif","contentUrl":"http:\/\/images.intellitxt.com\/ast\/adTypes\/mag-glass_10x10.gif"},{"@type":"BreadcrumbList","@id":"https:\/\/www.bhavyatechnologies.com\/blog\/making-usage-statistics-in-php-storing-the-data\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.bhavyatechnologies.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Making Usage Statistics in PHP \u2013 Storing the Data"}]},{"@type":"WebSite","@id":"https:\/\/www.bhavyatechnologies.com\/blog\/#website","url":"https:\/\/www.bhavyatechnologies.com\/blog\/","name":"Bhavya Technologies - Blog","description":"\u00a0Digital Marketing, Website design &amp; development company in Hyderabad, India","publisher":{"@id":"https:\/\/www.bhavyatechnologies.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.bhavyatechnologies.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.bhavyatechnologies.com\/blog\/#organization","name":"Bhavya Web Technologies","url":"https:\/\/www.bhavyatechnologies.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bhavyatechnologies.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.bhavyatechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/cropped-NewLogo.png","contentUrl":"https:\/\/www.bhavyatechnologies.com\/blog\/wp-content\/uploads\/2017\/07\/cropped-NewLogo.png","width":248,"height":100,"caption":"Bhavya Web Technologies"},"image":{"@id":"https:\/\/www.bhavyatechnologies.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/BhavyaWebTech\/","https:\/\/x.com\/bhavyatech","http:\/\/www.linkedin.com\/company\/bhavya-technologies\/","http:\/\/www.youtube.com\/user\/bhavyatechnologies"]},{"@type":"Person","@id":"https:\/\/www.bhavyatechnologies.com\/blog\/#\/schema\/person\/a8b972526a82dee1d674d1fcb5124895","name":"Bhavya Technologies","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bhavyatechnologies.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/fe762d42f67c5102549b2df80f35f4328850bd6b77a18d11070f369c3854d473?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/fe762d42f67c5102549b2df80f35f4328850bd6b77a18d11070f369c3854d473?s=96&d=mm&r=g","caption":"Bhavya Technologies"},"description":"We are team of young, energetic and dynamic members, focused on providing high quality website designing, website development and Internet Marketing services. With a team of such Bhavya member we always try and deliver high quality of project, exceeding client\u2019s expectation.","sameAs":["http:\/\/www.bhavyatechnologies.com"]}]}},"_links":{"self":[{"href":"https:\/\/www.bhavyatechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bhavyatechnologies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bhavyatechnologies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bhavyatechnologies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bhavyatechnologies.com\/blog\/wp-json\/wp\/v2\/comments?post=166"}],"version-history":[{"count":3,"href":"https:\/\/www.bhavyatechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/166\/revisions"}],"predecessor-version":[{"id":168,"href":"https:\/\/www.bhavyatechnologies.com\/blog\/wp-json\/wp\/v2\/posts\/166\/revisions\/168"}],"wp:attachment":[{"href":"https:\/\/www.bhavyatechnologies.com\/blog\/wp-json\/wp\/v2\/media?parent=166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bhavyatechnologies.com\/blog\/wp-json\/wp\/v2\/categories?post=166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bhavyatechnologies.com\/blog\/wp-json\/wp\/v2\/tags?post=166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}