PHP - Simple Visitor Count Using MySQLi
In this tutorial we will create a Simple Visitor Count using MySQLi. PHP is a server-side scripting language designed primarily for web development. SQLite provides an interface for accessing the database. It includes class interfaces to the SQL commands. And also it allows you to create SQL functions and aggregate using PHP. So Let's do the coding...
First you have to download & install XAMPP or any local server that run PHP scripts. Here's the link for XAMPP server https://www.apachefriends.org/index.html.
And this is the link for the bootstrap that i used for the layout design https://getbootstrap.com/.
Creating the database connection
Open your any kind of text editor(notepad++, etc..). Then just copy/paste the code below then name it conn.php.
Creating The Interface
This is where we will create a simple form for our application. To create the forms simply copy and write it into you text editor, then save it as index.php.
- <!DOCTYPE html>
- <html lang="en">
- <meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
- <link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
- <nav class="navbar navbar-default">
- <div class="container-fluid">
- <a class="navbar-brand" href="<a href="https://sourcecodester.com">Sourcecodester</a>
- " rel="nofollow">https://sourcecodester.com">Sourcecodester</a>
- </a> </div>
- <div class="col-md-3"></div>
- <div class="col-md-6 well">
- <h3 class="text-primary">PHP - Simple Visitor Count Using MySQLi</h3>
- <hr style="border-top:1px dotted;"/>
- <h4>Please refresh the browser to count</h4>
- <h3>Visitor have accessed this website <label class="text-primary"><?php include 'counter.php'?></label> times</h3>
Creating the Main Function
This code contains the main function of the application. This code will start counting when the visitor visit your page. To do this just copy and write these block of codes as shown below inside the text editor and save it as counter.php.
There you have it we successfully created a Simple Visitor Count using MySQLi. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!!!