Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // we want to store were the
- function getRealIpAddr()
- {
- if (!empty($_SERVER['HTTP_CLIENT_IP'])) //check ip from share internet
- {
- $ip=$_SERVER['HTTP_CLIENT_IP'];
- }
- elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //to check ip is pass from proxy
- {
- $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
- }
- else
- {
- $ip=$_SERVER['REMOTE_ADDR'];
- }
- return $ip;
- }
- function encryptPassword($Pass){
- $options = [
- 'cost' => 14,
- ];
- $Pass = password_hash($Pass, PASSWORD_BCRYPT, $options);
- return $Pass;
- }
- function hasMail($connection, $input_mail){
- // SQL Query To Fetch Complete Information Of User
- $query = mysql_query("SELECT 'email' FROM login WHERE email='$input_mail'", $connection);
- $row = mysql_fetch_assoc($query);
- $mail = $row['email'];
- if(isset($mail)){
- return True;
- }
- else
- {
- return False;
- }
- }
- $error=''; // Variable To Store Error Message
- if (isset($_POST['submit'])) {
- if (empty($_POST['username']) || empty($_POST['password'])) {
- $error = "Username or Password is invalid";
- }
- else
- {
- // Define user related variables
- $username = $_POST['username'];
- $password = $_POST['password'];
- $mail = $_POST['mail'];
- $ip = getRealIpAddr();
- $date_created = date("Y/m/d");
- // Establishing Connection with Server by passing server_name, user_id and password as a parameter
- $connection = mysql_connect("localhost", "root", "");
- // To protect MySQL injection for Security purpose
- $username = stripslashes($username);
- $password = stripslashes($password);
- $mail = stripslashes($mail);
- $username = mysql_real_escape_string($username);
- $password = mysql_real_escape_string($password);
- $mail = mysql_real_escape_string($mail);
- // Selecting Database
- $db = mysql_select_db("company", $connection);
- if(hasMail($connection, $mail)){
- mysql_close($connection);
- $error = "Denne e-mail er i brug!";
- }
- else
- {
- // encrypt password!
- $password = encryptPassword( $password );
- // SQL query to fetch information of registerd users and finds user match.
- //$query = mysql_query("select * from login where password='$password' AND username='$username'", $connection);
- //INSERT INTO `login`(`username`, `password`, `email`, `ip`, `created`) VALUES ([value-2],[value-3],[value-4],[value-5],[value-6])
- $query = mysql_query("
- INSERT INTO
- `login`(`username`, `password`, `email`, `ip`, `created`)
- VALUES ('$username', '$password', '$mail', '$ip', '$date_created')",
- $connection);
- mysql_close($connection); // Closing Connection
- session_start(); // Starting Session
- $_SESSION['login_user'] = $username;
- header('Location: profile.php');
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <head>
- <title>Signup Form</title>
- <link href="style.css" rel="stylesheet" type="text/css">
- </head>
- </head>
- <body>
- <div id="main">
- <h1>Ny Bruger</h1>
- <div id="login">
- <h2>Login Form</h2>
- <form action="" method="post">
- <label>Navn :</label>
- <input id="name" name="username" placeholder="" type="text">
- <label>Email :</label>
- <input id="mail" name="mail" placeholder="" type="text">
- <label>Password :</label>
- <input id="password" name="password" placeholder="**********" type="password">
- <input name="submit" type="submit" value=" Login ">
- <span><?php echo $error;?></span>
- </form>
- </div>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement