Auto Recognise Users via IP Address Through PHP/MySQLi v2 PHP Script


Auto Recognise Users via IP Address Through PHP/MySQLi v2 PHP Script

Introduction:
This tutorial will show you how to quickly identify your website users through their IP.

Database:
First we will need a database (mine is ‘fln’), a table – ‘test’, and columns with data. My columns are;

id, int, 5 length, primary key, auto increment
username, varchar, 255 length
ip, varchar, 255 length

The IP field does not have to be 255 characters long but it will help to avoid errors in case we accidentally input some data other than an IP address.

Connection:
Now we need to connect to our database through PHP and MySQLi, we do this through a connection statement.

 

     <?php
          $con = mysqli_connect('localhost', 'root', '', 'fln'); //server, username, password, database name
    ?>

 

IP:
Next we want to get the current visitor’s IP address. We can do this through a simple Server variable ‘Remote Address’. We store it in a string variable named ‘ipaddr’, standing for Internet Protocol Address.

 

 

    $ipaddr = $_SERVER['REMOTE_ADDR'];

 

Rows:
Finally we want to check to see if there are any pre-existing rows containing our visitors IP, if so, we output their possible username. Otherwise we say that there is no username found in association with their IP address.

 

 

    $q = mysqli_query($con, "SELECT * FROM `test` WHERE `ip`='$ipaddr'");
    if (mysqli_num_rows($q) > 0) {
          echo 'Is your username ' . mysqli_fetch_array($q)['username'] . '?';
    }else
          echo 'No username found by that IP address!';

 

Important:
IP addresses can be easily spoofed, so it is important not to use this as your only verification feature!

You may also want to tell the users that their IP is being logged, for your own security reasons.

Finished!
All done! Next tutorial (I will link here when it’s online) I will create the second part to this tutorial where we will allow any unrecognised users to register.

You may download my test DB from the button below this post. Please note; the IP is ‘127.0.0.1’ for anyone’s localhost, this is because I used my localhost to test this – plus I wouldn’t give out my IP.

 

 

 

Learn How to install Auto Recognise Users via IP Address Through PHP/MySQLi v2 PHP Script?



Find More related Auto Recognise Users via IP Address Through PHP/MySQLi v2 PHP Script



Auto PHP Script | Recogne PHP Script | Users PHP Script | Via PHP Script | Ip PHP Script | Address PHP Script | Through PHP Script | Php PHP Script | Mysqli PHP Script | V2 PHP Script | Php PHP Script | Script PHP Script | introduction PHP Script | Th PHP Script | Tutorial PHP Script | Will PHP Script | Show PHP Script | How PHP Script | To PHP Script | Quickly PHP Script | Identy PHP Script | R PHP Script | Webse PHP Script | Users PHP Script | Through PHP Script | Their PHP Script | Ip PHP Script | Database PHP Script | First PHP Script | 2021 Top 100 Auto PHP Script | Top 10 Recogne PHP Script | Top 50 Users PHP Script | 2021 Top 40 Via PHP Script | Top 100 Ip PHP Script | Top 50 Address PHP Script | 2021 Top 100 Through PHP Script | Top 20 Php PHP Script | Top 100 Mysqli PHP Script | Top 10 V2 PHP Script | Top 100 Php PHP Script | Top 200 Script PHP Script | Top 500 introduction PHP Script | Top 1000 Th PHP Script | Top 5000 Tutorial PHP Script | Top 50 Will PHP Script | Top 50 Show PHP Script | Top 50 How PHP Script | Top 50 To PHP Script | 2021 Top 50 Quickly PHP Script | Top 50 Identy PHP Script | Top 50 R PHP Script | Top 50 Webse PHP Script | Top 50 Users PHP Script | Top 20 Through PHP Script | Top 20 Their PHP Script | Top 20 Ip PHP Script | Top 10 Database PHP Script | Top 10 First PHP Script | Popular 100 Auto PHP Script | Popular 10 Recogne PHP Script | Popular 50 Users PHP Script | Popular 40 Via PHP Script | Popular 100 Ip PHP Script | Popular 50 Address PHP Script | Popular 100 Through PHP Script | Popular 20 Php PHP Script | Best 100 Mysqli PHP Script | Best 10 V2 PHP Script | Best 100 Php PHP Script | Best 200 Script PHP Script | Best 500 introduction PHP Script | Best 1000 Th PHP Script | Best 5000 Tutorial PHP Script | Popular 50 Will PHP Script | 2021 New 50 Show PHP Script | 2021 New 1000 How PHP Script | 2021 Top 500 To PHP Script | 2021 Best 500 Quickly PHP Script | 2021 New 10 Identy PHP Script | 2021 Popular 500 R PHP Script | 2021 Popular 20 Webse PHP Script | 2021 New 1050 Users PHP Script | 2021 Top 200 Through PHP Script | 2021 Top 4000 Their PHP Script | 2021 New 20 Ip PHP Script | 2021 Best 100 Database PHP Script | 2021 Best 120 First PHP Script |

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

Horje

Horje