SHARE
TWEET

Untitled

a guest Nov 6th, 2018 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3.     // we want to store were the
  4.     function getRealIpAddr()
  5.     {
  6.         if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
  7.         {
  8.             $ip=$_SERVER['HTTP_CLIENT_IP'];
  9.         }
  10.         elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
  11.         {
  12.             $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
  13.         }
  14.         else
  15.         {
  16.             $ip=$_SERVER['REMOTE_ADDR'];
  17.         }
  18.    
  19.         return $ip;
  20.    
  21.     }
  22.  
  23.     function encryptPassword($Pass){
  24.  
  25.         $options = [
  26.             'cost' => 14,
  27.         ];
  28.  
  29.         $Pass = password_hash($Pass, PASSWORD_BCRYPT, $options);
  30.  
  31.         return $Pass;
  32.  
  33.     }
  34.  
  35.     function hasMail($connection, $input_mail){
  36.  
  37.         // SQL Query To Fetch Complete Information Of User
  38.         $query = mysql_query("SELECT 'email' FROM login WHERE email='$input_mail'", $connection);
  39.  
  40.  
  41.         $row = mysql_fetch_assoc($query);
  42.  
  43.         $mail = $row['email'];
  44.  
  45.         if(isset($mail)){
  46.             return True;
  47.         }
  48.         else
  49.         {
  50.             return False;
  51.         }
  52.  
  53.     }
  54.  
  55.     $error=''; // Variable To Store Error Message
  56.     if (isset($_POST['submit'])) {
  57.  
  58.         if (empty($_POST['username']) || empty($_POST['password'])) {
  59.             $error = "Username or Password is invalid";
  60.         }
  61.             else
  62.         {
  63.  
  64.             // Define user related variables
  65.             $username   = $_POST['username'];
  66.             $password   = $_POST['password'];
  67.             $mail       = $_POST['mail'];
  68.  
  69.             $ip         = getRealIpAddr();
  70.             $date_created   = date("Y/m/d");
  71.  
  72.             // Establishing Connection with Server by passing server_name, user_id and password as a parameter
  73.             $connection = mysql_connect("localhost", "root", "");
  74.  
  75.             // To protect MySQL injection for Security purpose
  76.             $username   = stripslashes($username);
  77.             $password   = stripslashes($password);
  78.             $mail       = stripslashes($mail);
  79.  
  80.             $username   = mysql_real_escape_string($username);
  81.             $password   = mysql_real_escape_string($password);
  82.             $mail       = mysql_real_escape_string($mail);
  83.  
  84.             // Selecting Database
  85.             $db = mysql_select_db("company", $connection);
  86.  
  87.             if(hasMail($connection, $mail)){
  88.  
  89.                 mysql_close($connection);
  90.                 $error = "Denne e-mail er i brug!";
  91.  
  92.             }
  93.             else
  94.             {
  95.                 // encrypt password!
  96.                 $password = encryptPassword( $password );
  97.  
  98.                 // SQL query to fetch information of registerd users and finds user match.
  99.                 //$query = mysql_query("select * from login where password='$password' AND username='$username'", $connection);
  100.                 //INSERT INTO `login`(`username`, `password`, `email`, `ip`, `created`) VALUES ([value-2],[value-3],[value-4],[value-5],[value-6])
  101.                 $query = mysql_query("
  102.                     INSERT INTO
  103.                     `login`(`username`, `password`, `email`, `ip`, `created`)
  104.                     VALUES ('$username', '$password', '$mail', '$ip', '$date_created')",
  105.                     $connection);
  106.  
  107.                 mysql_close($connection); // Closing Connection
  108.  
  109.                 session_start(); // Starting Session
  110.  
  111.                 $_SESSION['login_user'] = $username;
  112.  
  113.                 header('Location: profile.php');
  114.  
  115.             }
  116.  
  117.            
  118.         }
  119.     }
  120. ?>
  121.  
  122. <!DOCTYPE html>
  123. <html>
  124. <head>
  125.     <head>
  126.             <title>Signup Form</title>
  127.         <link href="style.css" rel="stylesheet" type="text/css">
  128.     </head>
  129. </head>
  130. <body>
  131.  
  132.     <div id="main">
  133.         <h1>Ny Bruger</h1>
  134.         <div id="login">
  135.  
  136.         <h2>Login Form</h2>
  137.             <form action="" method="post">
  138.  
  139.             <label>Navn :</label>
  140.             <input id="name" name="username" placeholder="" type="text">
  141.  
  142.             <label>Email :</label>
  143.             <input id="mail" name="mail" placeholder="" type="text">
  144.  
  145.             <label>Password :</label>
  146.             <input id="password" name="password" placeholder="**********" type="password">
  147.  
  148.             <input name="submit" type="submit" value=" Login ">
  149.             <span><?php echo $error;?></span>
  150.             </form>
  151.         </div>
  152.     </div>
  153.  
  154. </body>
  155. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top