{"id":772,"date":"2018-09-04T11:15:25","date_gmt":"2018-09-04T06:15:25","guid":{"rendered":"https:\/\/www.edopedia.com\/blog\/?p=772"},"modified":"2022-07-01T21:40:54","modified_gmt":"2022-07-01T16:40:54","slug":"how-to-create-website-visitor-counter-php-mysql","status":"publish","type":"post","link":"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/","title":{"rendered":"How to Create Website Visitor Counter in PHP and MySQL"},"content":{"rendered":"<p>Being able to count the number of visitors on each web page of your website will definitely help you in multiple ways. The most important one is that it allows you to understand what people are looking for on your website. In this tutorial, I&#8217;ll guide you about how you can add a <strong>website visitor counter<\/strong> on your own website in a step by step manner.<\/p>\n<p>I&#8217;ll be using <strong>PHP and MySQL<\/strong> for the basic functionality but also use a little bit <a href=\"https:\/\/www.edopedia.com\/courses\/html\"><strong>HTML5<\/strong><\/a> code to depict a real-world scenario.<\/p>\n<p>Just in case you are new to the Web Development field and want to earn money by creating professional websites. Then, I would highly recommend you to take these courses from Udemy.<\/p>\n<ul>\n<li><a href=\"https:\/\/bit.ly\/3I7fehi\" target=\"_blank\" rel=\"noopener noreferrer\">The Complete 2021 PHP Full Stack Web Developer Bootcamp<\/a><\/li>\n<li><a href=\"https:\/\/bit.ly\/3R2EkC8\" target=\"_blank\" rel=\"noopener noreferrer\">Build a Social Network from Scratch: JavaScript + PHP + MySQL<\/a><\/li>\n<li><a href=\"https:\/\/bit.ly\/3AgZ0jV\" target=\"_blank\" rel=\"noopener noreferrer\">Create a Netflix clone from Scratch: JavaScript + PHP + MySQL<\/a><\/li>\n<li><a href=\"https:\/\/bit.ly\/3bBZ0k5\" target=\"_blank\" rel=\"noopener noreferrer\">Make a Spotify Clone from Scratch: JavaScript + PHP + MySQL<\/a><\/li>\n<\/ul>\n<p>Anyways, let&#8217;s take a look at what you will be learning in this tutorial.<\/p>\n<hr \/>\n<h2>Table of Contents<\/h2>\n<ul>\n<li>Basic functionality of this project<\/li>\n<li>Setup database and tables for website visitor counter<\/li>\n<li>Files and folder used in this tutorial<\/li>\n<li>Connect to database<\/li>\n<li>Create PHP functions to handle unique visitor counter<\/li>\n<li>Create few web pages to count visits<\/li>\n<li>Download website visitor counter<\/li>\n<\/ul>\n<hr \/>\n<h2>Basic functionality of this project<\/h2>\n<ul>\n<li>It allows us to count total website views.<\/li>\n<li>It allows us to count number of visitors on a single web page.<\/li>\n<li>It makes use of visitor&#8217;s IP address to only count unique views.<\/li>\n<\/ul>\n<hr \/>\n<h2>Setup database and tables for website visitor counter<\/h2>\n<p>Basically we need a database for two purposes. First of all we will use it to store data for each web page of our website. Secondly we have to keep a record of previous visitors which help us figure out whether the new visitor is unique or not.<\/p>\n<p>Let&#8217;s open your phpMyAdmin and create a database named &#8220;website_visitor_counter&#8221;. Or simply use the below SQL query.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\">CREATE DATABASE website_visitor_counter;<\/pre>\n<p>Now move on and add two tables &#8220;pages&#8221; and &#8220;page_views&#8221; in the newly created database. You can make use of the below SQL queries.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\">CREATE TABLE pages\n(\n  id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,\n  total_views INTEGER UNSIGNED NOT NULL,\n  \n  PRIMARY KEY (id)\n);<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\">CREATE TABLE page_views\n(\n  visitor_ip VARCHAR(255) NOT NULL,\n  page_id INTEGER UNSIGNED NOT NULL,\n  \n  FOREIGN KEY (page_id) REFERENCES pages(id) ON DELETE CASCADE ON UPDATE CASCADE\n);<\/pre>\n<h3>Use of each database table:-<\/h3>\n<ul>\n<li><strong>pages<\/strong>\u00a0&#8211;\u00a0This table is used to store total views of each web page.<\/li>\n<li><strong>page_views<\/strong>\u00a0&#8211;\u00a0The main purpose of this database table is to maintain a record of every unique visit because we will need it in future to check whether the new visitor is unique or not.<\/li>\n<\/ul>\n<p>In this tutorial we will be counting hits on three web pages. So, let&#8217;s add three rows in the &#8220;pages&#8221; table (one row for each web page). Use the below SQL INSERT query.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"sql\">INSERT INTO pages (total_views)\nVALUES (0),(0),(0);<\/pre>\n<hr \/>\n<h2>Files and folder used in this tutorial<\/h2>\n<ul>\n<li><strong>includes<\/strong> &#8211; (This folder is used to group files that are included in other files)\n<ul>\n<li><strong>db_connect.php<\/strong> &#8211; (This file is used to create database connection)<\/li>\n<li><strong>functions.php<\/strong> &#8211; (This file is used to group all user-defined PHP functions)<\/li>\n<li><strong>header.php<\/strong> &#8211; (This file contains the header of web page)<\/li>\n<li><strong>footer.php<\/strong> &#8211; (This file contains the footer of web page)<\/li>\n<\/ul>\n<\/li>\n<li><strong>index.php<\/strong> &#8211; (Main page of website, only used to display total website views)<\/li>\n<li><strong>page_1.php<\/strong> &#8211; (Contains code for first web page)<\/li>\n<li><strong>page_2.php<\/strong> &#8211; (Contains code for second web page)<\/li>\n<li><strong>page_3.php<\/strong> &#8211; (Contains code for third web page)<\/li>\n<\/ul>\n<p>Create these files and folder before proceeding to next step.<\/p>\n<hr \/>\n<h2>Connect to database<\/h2>\n<p>Connecting to a MySQL database using PHP is a really simple and straightforward procedure. Copy\/Paste the below PHP code inside your &#8220;db_connect.php&#8221; file and save it.<\/p>\n<h4>db_connect.php<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">&lt;?php\n$db_host = \"localhost\";               \/\/ Database Host\n$db_user = \"root\";                    \/\/ Database User\n$db_pass = \"\";                        \/\/ Database Password\n$db_name = \"website_visitor_counter\"; \/\/ Database Name\n\n$conn = mysqli_connect($db_host, $db_user, $db_pass, $db_name); \/\/ Connect to Database\n\nif(!$conn) \/\/ Check connection\n{\n  die(\"Connection failed: \" . mysqli_connect_error()); \/\/ Display error if not connected\n}\n?&gt;<\/pre>\n<p>A point to be noted is that you may need to change the values of above PHP variables according to your specific environment.<\/p>\n<hr \/>\n<h2>Create PHP functions to handle unique visitor counter<\/h2>\n<p>Now it&#8217;s time to take a look at the core part of this project where we will be creating three PHP functions to define the logic and handle the overall functionality of a website hit counter.<\/p>\n<p>Here&#8217;s the contents of our &#8220;functions.php&#8221; file.<\/p>\n<h4>functions.php<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">&lt;?php\nfunction total_views($conn, $page_id = null)\n{\n  if($page_id === null)\n  {\n    \/\/ count total website views\n    $query = \"SELECT sum(total_views) as total_views FROM pages\";\n    $result = mysqli_query($conn, $query);\n    \n    if(mysqli_num_rows($result) &gt; 0)\n    {\n      while($row = $result-&gt;fetch_assoc())\n      {\n        if($row['total_views'] === null)\n        {\n          return 0;\n        }\n        else\n        {\n          return $row['total_views'];\n        }\n      }\n    }\n    else\n    {\n      return \"No records found!\";\n    }\n  }\n  else\n  {\n    \/\/ count specific page views\n    $query = \"SELECT total_views FROM pages WHERE id='$page_id'\";\n    $result = mysqli_query($conn, $query);\n    \n    if(mysqli_num_rows($result) &gt; 0)\n    {\n      while($row = $result-&gt;fetch_assoc())\n      {\n        if($row['total_views'] === null)\n        {\n          return 0;\n        }\n        else\n        {\n          return $row['total_views'];\n        }\n      }\n    }\n    else\n    {\n      return \"No records found!\";\n    }\n  }\n}\n\n\n\nfunction is_unique_view($conn, $visitor_ip, $page_id)\n{\n  $query = \"SELECT * FROM page_views WHERE visitor_ip='$visitor_ip' AND page_id='$page_id'\";\n  $result = mysqli_query($conn, $query);\n  \n  if(mysqli_num_rows($result) &gt; 0)\n  {\n    return false;\n  }\n  else\n  {\n    return true;\n  }\n}\n\n\n\nfunction add_view($conn, $visitor_ip, $page_id)\n{\n  if(is_unique_view($conn, $visitor_ip, $page_id) === true)\n  {\n    \/\/ insert unique visitor record for checking whether the visit is unique or not in future.\n    $query = \"INSERT INTO page_views (visitor_ip, page_id) VALUES ('$visitor_ip', '$page_id')\";\n    \n    if(mysqli_query($conn, $query))\n    {\n      \/\/ At this point unique visitor record is created successfully. Now update total_views of specific page.\n      $query = \"UPDATE pages SET total_views = total_views + 1 WHERE id='$page_id'\";\n      \n      if(!mysqli_query($conn, $query))\n      {\n        echo \"Error updating record: \" . mysqli_error($conn);\n      }\n    }\n    else\n    {\n      echo \"Error inserting record: \" . mysqli_error($conn);\n    }\n  }\n}\n?&gt;<\/pre>\n<h3>Explanation of above created PHP functions:<\/h3>\n<ul>\n<li><strong>total_views($conn, $page_id = null)<\/strong> &#8211; This function is used to retrieve total views of website or a specific page in a website.<\/li>\n<li><strong>is_unique_view($conn, $visitor_ip, $page_id)<\/strong> &#8211; This function takes the visitor&#8217;s IP address and ID of a page to check whether the visitor has already viewed the page or not.<\/li>\n<li><strong>add_view($conn, $visitor_ip, $page_id)<\/strong> &#8211; If the visitor is unique then this function will add his\/her record inside the &#8220;page_views&#8221; table and also increment the &#8220;total_views&#8221; column of visited web page by one inside &#8220;pages&#8221; table.<\/li>\n<\/ul>\n<hr \/>\n<h2>Create few web pages to count visits<\/h2>\n<p>In this section we will be creating four web pages to count unique visitors on our website. The files used for these web pages are as follow:<\/p>\n<ul>\n<li><strong>index.php<\/strong><\/li>\n<li><strong>page_1.php<\/strong><\/li>\n<li><strong>page_2.php<\/strong><\/li>\n<li><strong>page_3.php<\/strong><\/li>\n<\/ul>\n<p>Also remember that I&#8217;ve used two more files &#8220;header.php&#8221; and &#8220;footer.php&#8221; just to separate the header and footer section of our web pages. This way we will be able to reuse same code in multiple files and it makes it very easy to edit as we just need to modify one file.<\/p>\n<p>Basically the &#8220;header.php&#8221; file contains few links to navigate on different web pages of this project. Here&#8217;s the code for this file.<\/p>\n<h4>header.php<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n  &lt;head&gt;\n    &lt;title&gt;Website Visitor Counter&lt;\/title&gt;\n  &lt;\/head&gt;\n  \n  &lt;body&gt;\n    &lt;header&gt;\n      &lt;ul&gt;\n        &lt;li&gt;&lt;a href=\"index.php\"&gt;Main Page&lt;\/a&gt;&lt;\/li&gt;\n        &lt;li&gt;&lt;a href=\"page_1.php\"&gt;Page 1&lt;\/a&gt;&lt;\/li&gt;\n        &lt;li&gt;&lt;a href=\"page_2.php\"&gt;Page 2&lt;\/a&gt;&lt;\/li&gt;\n        &lt;li&gt;&lt;a href=\"page_3.php\"&gt;Page 3&lt;\/a&gt;&lt;\/li&gt;\n      &lt;\/ul&gt;\n    &lt;\/header&gt;<\/pre>\n<p>&#8220;footer.php&#8221; only contains few ending tags of our web pages. Check the code below:<\/p>\n<h4>footer.php<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">  &lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>&#8220;index.php&#8221; file is just like the main\/home page of a website. We will only use it to display total website views. Here&#8217;s the code for this file.<\/p>\n<h4>index.php<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">&lt;?php\nrequire_once('includes\/db_connect.php'); \/\/ Database connection file\nrequire_once('includes\/functions.php');  \/\/ PHP functions file\n?&gt;\n\n&lt;!-- header file --&gt;\n&lt;?php require_once('includes\/header.php'); ?&gt;\n\n&lt;div&gt;\n  &lt;?php\n  $total_website_views = total_views($conn); \/\/ Returns total website views\n  echo \"&lt;strong&gt;Total Website Views:&lt;\/strong&gt; \" . $total_website_views;\n  ?&gt;\n&lt;\/div&gt;\n\n&lt;div style=\"color: red;\"&gt;Note: This page only displays the total views of website.&lt;div&gt;\n\n&lt;!-- footer file --&gt;\n&lt;?php require_once('includes\/footer.php'); ?&gt;<\/pre>\n<p>Does this code looks complex? Don&#8217;t worry! Let me explain&#8230;<\/p>\n<ul>\n<li>In first PHP block we are including two PHP files &#8220;db_connect.php&#8221; and &#8220;functions.php&#8221;.<\/li>\n<li>After that we include the header of our web page.<\/li>\n<li>Next we created a &lt;div&gt;&lt;\/div&gt; element where we called the &#8220;total_views($conn)&#8221; function. You may have noticed that we have only provided one database connection variable as parameter, it&#8217;s because the second &#8220;page_id&#8221; parameter is optional. This way the function will return the total website views and store it inside the specified variable. After that we are outputting the value of that variable on screen.<\/li>\n<li>On next line I&#8217;ve simply displayed a note.<\/li>\n<li>At last the &#8220;footer.php&#8221; file is included in the web page.<\/li>\n<\/ul>\n<p>&#8220;page_1.php&#8221;, &#8220;page_2.php&#8221; and &#8220;page_3.php&#8221; are like other web pages on a website. So, we are going to track them separately just to show you the correct method of how you should implement website visitor counter on your personal or business website.<\/p>\n<h4>page_1.php<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">&lt;?php\nrequire_once('includes\/db_connect.php'); \/\/ Database connection file\nrequire_once('includes\/functions.php');  \/\/ PHP functions file\n\n$page_id = 1;\n$visitor_ip = $_SERVER['REMOTE_ADDR']; \/\/ stores IP address of visitor in variable\n\nadd_view($conn, $visitor_ip, $page_id);\n?&gt;\n\n&lt;!-- header file --&gt;\n&lt;?php require_once('includes\/header.php'); ?&gt;\n\n&lt;div&gt;\n  &lt;?php\n  $total_page_views = total_views($conn, $page_id); \/\/ Returns total views of this page\n  echo \"&lt;strong&gt;Total Views of this Page:&lt;\/strong&gt; \" . $total_page_views;\n  ?&gt;\n&lt;\/div&gt;\n\n&lt;!-- footer file --&gt;\n&lt;?php require_once('includes\/footer.php'); ?&gt;<\/pre>\n<h4>page_2.php<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">&lt;?php\nrequire_once('includes\/db_connect.php'); \/\/ Database connection file\nrequire_once('includes\/functions.php');  \/\/ PHP functions file\n\n$page_id = 2;\n$visitor_ip = $_SERVER['REMOTE_ADDR']; \/\/ stores IP address of visitor in variable\n\nadd_view($conn, $visitor_ip, $page_id);\n?&gt;\n\n&lt;!-- header file --&gt;\n&lt;?php require_once('includes\/header.php'); ?&gt;\n\n&lt;div&gt;\n  &lt;?php\n  $total_page_views = total_views($conn, $page_id); \/\/ Returns total views of this page\n  echo \"&lt;strong&gt;Total Views of this Page:&lt;\/strong&gt; \" . $total_page_views;\n  ?&gt;\n&lt;\/div&gt;\n\n&lt;!-- footer file --&gt;\n&lt;?php require_once('includes\/footer.php'); ?&gt;<\/pre>\n<h4>page_3.php<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"php\">&lt;?php\nrequire_once('includes\/db_connect.php'); \/\/ Database connection file\nrequire_once('includes\/functions.php');  \/\/ PHP functions file\n\n$page_id = 3;\n$visitor_ip = $_SERVER['REMOTE_ADDR']; \/\/ stores IP address of visitor in variable\n\nadd_view($conn, $visitor_ip, $page_id);\n?&gt;\n\n&lt;!-- header file --&gt;\n&lt;?php require_once('includes\/header.php'); ?&gt;\n\n&lt;div&gt;\n  &lt;?php\n  $total_page_views = total_views($conn, $page_id); \/\/ Returns total views of this page\n  echo \"&lt;strong&gt;Total Views of this Page:&lt;\/strong&gt; \" . $total_page_views;\n  ?&gt;\n&lt;\/div&gt;\n\n&lt;!-- footer file --&gt;\n&lt;?php require_once('includes\/footer.php'); ?&gt;<\/pre>\n<p>&#8220;page_1.php&#8221;, &#8220;page_2.php&#8221; and &#8220;page_3.php&#8221; are almost similar to the &#8220;index.php&#8221; file with few exceptions.<\/p>\n<ul>\n<li>We are using a &#8220;$page_id&#8221; variable to store the ID of that specific page, we got this ID from the database table &#8220;pages&#8221;.<\/li>\n<li>After that we are using &#8220;$_SERVER[&#8216;REMOTE_ADDR&#8217;]&#8221; to get the IP address of visitor.<\/li>\n<li>Now we simply pass the above two variables to our &#8220;add_view($conn, $visitor_ip, $page_id)&#8221; function.<\/li>\n<li>We also pass the &#8220;$page_id&#8221; variable to &#8220;total_views($conn, $page_id)&#8221; function, which will return total unique views of a specific web page.<\/li>\n<\/ul>\n<hr \/>\n<h2>Download website visitor counter<\/h2>\n<p><a class=\"ep_link_major\" href=\"https:\/\/www.edopedia.com\/assets\/downloads\/static\/website_visitor_counter.zip\" target=\"_blank\" rel=\"noopener noreferrer\" download=\"\">Download<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Being able to count the number of visitors on each web page of your website will definitely help you in multiple ways. The most important one is that it allows you to understand what people are looking for on your website. In this tutorial, I&#8217;ll guide you about how you can add a website visitor &#8230; <a title=\"How to Create Website Visitor Counter in PHP and MySQL\" class=\"read-more\" href=\"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/\" aria-label=\"Read more about How to Create Website Visitor Counter in PHP and MySQL\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":817,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[112],"tags":[],"class_list":["post-772","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Create Website Visitor Counter in PHP and MySQL<\/title>\n<meta name=\"description\" content=\"Being able to count the number of visitors on each web page of your website will definitely help you in multiple ways. In this tutorial, I&#039;ll guide you about how you can add a website visitor counter on your own website in a step by step manner.\" \/>\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.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Create Website Visitor Counter in PHP and MySQL\" \/>\n<meta property=\"og:description\" content=\"Being able to count the number of visitors on each web page of your website will definitely help you in multiple ways. In this tutorial, I&#039;ll guide you about how you can add a website visitor counter on your own website in a step by step manner.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/\" \/>\n<meta property=\"og:site_name\" content=\"Edopedia\" \/>\n<meta property=\"article:author\" content=\"trulyfurqan\" \/>\n<meta property=\"article:published_time\" content=\"2018-09-04T06:15:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-01T16:40:54+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2018\/09\/post_image_3_1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"880\" \/>\n\t<meta property=\"og:image:height\" content=\"495\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Furqan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Furqan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Create Website Visitor Counter in PHP and MySQL","description":"Being able to count the number of visitors on each web page of your website will definitely help you in multiple ways. In this tutorial, I'll guide you about how you can add a website visitor counter on your own website in a step by step manner.","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.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/","og_locale":"en_US","og_type":"article","og_title":"How to Create Website Visitor Counter in PHP and MySQL","og_description":"Being able to count the number of visitors on each web page of your website will definitely help you in multiple ways. In this tutorial, I'll guide you about how you can add a website visitor counter on your own website in a step by step manner.","og_url":"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/","og_site_name":"Edopedia","article_author":"trulyfurqan","article_published_time":"2018-09-04T06:15:25+00:00","article_modified_time":"2022-07-01T16:40:54+00:00","og_image":[{"width":880,"height":495,"url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2018\/09\/post_image_3_1.jpg","type":"image\/jpeg"}],"author":"Furqan","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Furqan","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/#article","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/"},"author":{"name":"Furqan","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339"},"headline":"How to Create Website Visitor Counter in PHP and MySQL","datePublished":"2018-09-04T06:15:25+00:00","dateModified":"2022-07-01T16:40:54+00:00","mainEntityOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/"},"wordCount":1241,"commentCount":25,"publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2018\/09\/post_image_3_1.jpg","articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/","url":"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/","name":"How to Create Website Visitor Counter in PHP and MySQL","isPartOf":{"@id":"https:\/\/www.edopedia.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/#primaryimage"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2018\/09\/post_image_3_1.jpg","datePublished":"2018-09-04T06:15:25+00:00","dateModified":"2022-07-01T16:40:54+00:00","description":"Being able to count the number of visitors on each web page of your website will definitely help you in multiple ways. In this tutorial, I'll guide you about how you can add a website visitor counter on your own website in a step by step manner.","breadcrumb":{"@id":"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/#primaryimage","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2018\/09\/post_image_3_1.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2018\/09\/post_image_3_1.jpg","width":880,"height":495,"caption":"How to Create Website Visitor Counter in PHP and MySQL"},{"@type":"BreadcrumbList","@id":"https:\/\/www.edopedia.com\/blog\/how-to-create-website-visitor-counter-php-mysql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.edopedia.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Create Website Visitor Counter in PHP and MySQL"}]},{"@type":"WebSite","@id":"https:\/\/www.edopedia.com\/blog\/#website","url":"https:\/\/www.edopedia.com\/blog\/","name":"Edopedia","description":"Coding\/Programming Blog","publisher":{"@id":"https:\/\/www.edopedia.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.edopedia.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.edopedia.com\/blog\/#organization","name":"Edopedia","url":"https:\/\/www.edopedia.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","contentUrl":"https:\/\/www.edopedia.com\/blog\/wp-content\/uploads\/2017\/10\/edopedia_icon_text_10.jpg","width":400,"height":100,"caption":"Edopedia"},"image":{"@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.edopedia.com\/blog\/#\/schema\/person\/3951cb19e3aa56df09e408c98aa02339","name":"Furqan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e5e68aef3ad8f0b83d56f4953c512c8e57bd2e6dc64daec33b5d0495d9058f51?s=96&d=mm&r=g","caption":"Furqan"},"description":"Well. I've been working for the past three years as a web designer and developer. I have successfully created websites for small to medium sized companies as part of my freelance career. During that time I've also completed my bachelor's in Information Technology.","sameAs":["http:\/\/www.edopedia.com\/blog\/","trulyfurqan"],"url":"https:\/\/www.edopedia.com\/blog\/author\/furqan\/"}]}},"_links":{"self":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/772","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/comments?post=772"}],"version-history":[{"count":0,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/posts\/772\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media\/817"}],"wp:attachment":[{"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/media?parent=772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/categories?post=772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.edopedia.com\/blog\/wp-json\/wp\/v2\/tags?post=772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}