User authentication with notification of the system IP PHP Script


User authentication with notification of the system IP PHP Script

his code will allows you to login with and notify you if your machine to be recognized to the system, with the help of the PHP codes that calls your IP Address.

Please see below and copy/paste to your web server then run to your browser.

 

 

    <?php
          session_start();
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html" rel="nofollow">http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html</a> xmlns="<a href="http://www.w3.org/1999/xhtml">
    " rel="nofollow">http://www.w3.org/1999/xhtml">
    </a>      <head>
                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
                <script type="text/javascript" src="js/jQuery.js"></script>
                <script type="text/javascript" src="js/notificationBox.js"></script>
          <style type="text/css">
                #mask {
                  position:absolute;
                  left:0;
                  top:0;
                  z-index:9000;
                  background-color:#eee;
                  display:none;
                }  
                #boxes .window {
                  position:absolute;
                  left:0;
                  top:0;
                  width:440px;
                  height:100px;
                  display:none;
                  z-index:9999;
                  padding:20px;
                }
                #boxes #dialog {
                      font-family:verdana;
                      width:375px; 
                      height:103px;
                      padding:10px;
                      background-color:#ffffff;
                      border-top-left-radius: 5pt;
                      border-top-right-radius: 5pt;
                      border-botttom-left-radius: 5pt;
                      border-bottom-right-radius: 5pt;
                      border-bottom-left-radius: 5pt;
                      border: 2px solid lightgrey;
                }
          </style>
          </head>
          <body>
                <?php
                            function get_ip_address() {
                                  $ip_keys = array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR');
                                  foreach ($ip_keys as $key) {
                                        if (array_key_exists($key, $_SERVER) === true) {
                                              foreach (explode(',', $_SERVER[$key]) as $ip) {
                                              // trim for safety measures
                                              $ip = trim($ip);
                                              // attempt to validate IP
                                              if (validate_ip($ip)) {
                                                    return $ip;
                                              }
                                              }
                                        }
                                  }
     
                                  return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : false;
                            }
     
                            /*** Ensures an ip address is both a valid IP and does not fall within
                            * a private network range.*/
                            function validate_ip($ip) {
                                  if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) === false) {
                                  return false;
                                  }
                                  return true;
                            }
                            $setIP  = get_ip_address();
                      ?>
                <?php
                //declaring variables
                      $_dbHost = "localhost";
                      $_dbUser = "root";
                      $_dbPass = "";
                      $_dbName = "tutorials";
                      $_connFailed = "Database connection failed.";
                      $_dbConnFailed = "Database selection failed.";
                ?>
                <?php
                      //validate host connection
                      if(!mysql_connect($_dbHost, $_dbUser, $_dbPass)) {
                            echo $_connFailed;
                      }
                      //validate database 
                      if(!mysql_select_db($_dbName)) {
                            echo $_dbConnFailed;
                      } 
                ?>
                <?php
     
                      if(isset($_POST["login"])) {
                            $uName = trim($_POST["uName"]);
                            $uPass = trim($_POST["uPass"]);
                            $_uIP = trim($_POST["uIP"]);
     
                            $loginQry = "SELECT * FROM users WHERE uName='$uName' AND uPass='$uPass' AND uIP='$_uIP'";
                            $result = mysql_query($loginQry) or die ("Database query failed: $loginQry" . mysql_error());
                            $userRaw = mysql_fetch_array($result);
     
                            if($userRaw) {
                                  $_SESSION['id'] = $userRaw['id'];
                                        echo "<script>windows: location='index.php?id=$uName'</script>";
                            } else {
                                  $msgOut = "Sorry you can't login. Please check your input username and password.";
                            }
                      }
          ?>
                <div>
                      <?php echo $msgOut?>
                </div>
                <div>
     
                <fieldset>
                <legend>User Authentication</legend>
                <form action="login.php" method="post">
                      Username:
                      <br />
                      <input type="text" name="uName" placeholder="Username!">
                      <br />
                      <br />
                      Password:
                      <br />
                      <input type="password" name="uPass" placeholder="Password!">
                      <br />
                      <br />
                      IP Address:
                      <br />
                      <input type="text" name="uIP" value="<?php echo $setIP; ?>">
                      <br /><br />
                      <input type="submit" name="login" value="Login"><input type="reset" value="Clear">
                </form> 
                <br />
                <a href="login.php">Not yet registered?</a>      
                </fieldset>
                </div>
     
                <?php
                      $_uIP = $setIP;
                      $query = mysql_query("Select * From users Where uIP = '$_uIP'") or die ("Database query failed." . mysql_error());
                            if(mysql_num_rows($query)) {
                      } else {
                      ?>
                            <div id="boxes" onClick="window.location='register.php'">
                                  <div style="top: 199.5px; left: 551.5px; display: none;" id="dialog" class="window">
                                        <b style="color: #336699;">System Notification</b>
                                        <hr />
                                        <div>
                                              <font color="red"><b>Your machine is not recognized. Please ask for assistance to your system administrator.</b></font>
                                        </div>
                                  </div>
                                  <div style="width: 1478px; height: 202px; display: none; opacity: 0.8;" id="mask">
                                  </div>
                            </div>
                      <?php
                      }
                      ?>
                      <?php
                            //$query = mysql_query("Select * From users Where ");
                      ?>
          </body>
          </html>

 

 

Hope this code will help you guys. Please leave your comments below or any suggestions. Any problem with your web development just inquire me with this email: [email protected] 🙂 happy codings…

 

 

Learn How to install User authentication with notification of the system IP PHP Script?



Find More related User authentication with notification of the system IP PHP Script



User PHP Script | Authentication PHP Script | Notication PHP Script | Of PHP Script | The PHP Script | System PHP Script | Ip PHP Script | Php PHP Script | Script PHP Script | H PHP Script | Code PHP Script | Will PHP Script | allows PHP Script | To PHP Script | Login PHP Script | Noty PHP Script | R PHP Script | Machine PHP Script | To PHP Script | Be PHP Script | Recognized PHP Script | To PHP Script | The PHP Script | System PHP Script | The PHP Script | Help PHP Script | 2021 Top 100 User PHP Script | Top 10 Authentication PHP Script | Top 50 Notication PHP Script | 2021 Top 40 Of PHP Script | Top 100 The PHP Script | Top 50 System PHP Script | 2021 Top 100 Ip PHP Script | Top 20 Php PHP Script | Top 100 Script PHP Script | Top 10 H PHP Script | Top 100 Code PHP Script | Top 200 Will PHP Script | Top 500 allows PHP Script | Top 5000 To PHP Script | Top 50 Login PHP Script | Top 50 Noty PHP Script | 2021 Top 50 R PHP Script | Top 50 Machine PHP Script | Top 50 To PHP Script | Top 50 Be PHP Script | Top 50 Recognized PHP Script | Top 20 To PHP Script | Top 20 The PHP Script | Top 20 System PHP Script | Top 10 The PHP Script | Top 10 Help PHP Script | Popular 100 User PHP Script | Popular 10 Authentication PHP Script | Popular 50 Notication PHP Script | Popular 40 Of PHP Script | Popular 100 The PHP Script | Popular 50 System PHP Script | Popular 100 Ip PHP Script | Popular 20 Php PHP Script | Best 100 Script PHP Script | Best 10 H PHP Script | Best 100 Code PHP Script | Best 200 Will PHP Script | Best 500 allows PHP Script | Best 5000 To PHP Script | Popular 50 Login PHP Script | 2021 New 500 Noty PHP Script | 2021 Best 500 R PHP Script | 2021 New 10 Machine PHP Script | 2021 Popular 500 To PHP Script | 2021 Popular 20 Be PHP Script | 2021 New 1050 Recognized PHP Script | 2021 Top 200 To PHP Script | 2021 Top 4000 The PHP Script | 2021 New 20 System PHP Script | 2021 Best 100 The PHP Script | 2021 Best 120 Help PHP Script |

Have any Question or Comment?

Leave a Reply

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

Horje

Horje