2 4 6 8 10 | <h2 class='form-signin-heading'>Please Login</h2> <span class='input-group-addon'id='basic-addon1'>@</span> <input type='text'name='username'class='form-control'placeholder='Username'required> <label for='inputPassword'class='sr-only'>Password</label> <input type='password'name='password'id='inputPassword'class='form-control'placeholder='Password'required> <button class='btn btn-lg btn-primary btn-block'type='submit'>Login</button> <a class='btn btn-lg btn-primary btn-block'href='register.php'>Register</a> |
2 4 6 8 10 | <link rel='stylesheet'href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' > <!-- Optional theme --> <link rel='stylesheet'href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css' > <link rel='stylesheet'href='styles.css' > <!-- Latest compiled and minified JavaScript --> <script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'></script> |
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 | padding-top:40px; background-color:#eee; max-width:330px; margin:0auto; .form-signin .form-signin-heading, margin-bottom:10px; .form-signin .checkbox { } position:relative; -webkit-box-sizing:border-box; box-sizing:border-box; font-size:16px; .form-signin .form-control:focus { } margin-bottom:-1px; border-bottom-left-radius:0; .form-signin input[type='password'] { border-top-left-radius:0; } |
2 4 6 8 | $connection=mysqli_connect('localhost','root','Rvm@i[9)0?~='); die('Database Connection Failed'.mysqli_error($connection)); $select_db=mysqli_select_db($connection,'test'); die('Database Selection Failed'.mysqli_error($connection)); |
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 | session_start(); //3. If the form is submitted or not. if(isset($_POST['username'])andisset($_POST['password'])){ $username=$_POST['username']; //3.1.2 Checking the values are existing in the database or not $query='SELECT * FROM `user` WHERE username='$username' and password='$password'; $result=mysqli_query($connection,$query)ordie(mysqli_error($connection)); //3.1.2 If the posted values are equal to the database values, then session will be created for the user. $_SESSION['username']=$username; //3.1.3 If the login credentials doesn't match, he will be shown with an error message. } //3.1.4 if the user is logged in Greets the user with message $username=$_SESSION['username']; '; '; //3.2 When the user visits the page first time, simple login form will be displayed. |
2 4 | session_start(); header('Location: login.php'); |
2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 | session_start(); //3. If the form is submitted or not. if(isset($_POST['username'])andisset($_POST['password'])){ $username=$_POST['username']; //3.1.2 Checking the values are existing in the database or not $query='SELECT * FROM `user` WHERE username='$username' and password='$password'; $result=mysqli_query($connection,$query)ordie(mysqli_error($connection)); //3.1.2 If the posted values are equal to the database values, then session will be created for the user. $_SESSION['username']=$username; //3.1.3 If the login credentials doesn't match, he will be shown with an error message. } //3.1.4 if the user is logged in Greets the user with message $username=$_SESSION['username']; '; '; //3.2 When the user visits the page first time, simple login form will be displayed. <html> <title>User Login Using PHP&MySQL</title> <!--Latest compiled andminified CSS--> <link rel='stylesheet'href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'> <!--Optional theme--> <link rel='stylesheet'href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css'> <link rel='stylesheet'href='styles.css'> <!--LatestcompiledandminifiedJavaScript--> <script src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js'></script> <body> <div class='container'> <?phpif(isset($fmsg)){?><div class='alert alert-danger'role='alert'><?phpecho$fmsg;?></div><?php}?> <div class='input-group'> <span class='input-group-addon'id='basic-addon1'>@</span> <input type='text'name='username'class='form-control'placeholder='Username'required> <label for='inputPassword'class='sr-only'>Password</label> <input type='password'name='password'id='inputPassword'class='form-control'placeholder='Password'required> <button class='btn btn-lg btn-primary btn-block'type='submit'>Login</button> <aclass='btn btn-lg btn-primary btn-block'href='register.php'>Register</a> </div> </body> </html> |
2 4 | $username=mysqli_real_escape_string($connection,$_POST['username']); } |
2 4 6 8 10 | $sql='SELECT * FROM `user` WHERE username='$username' AND password='$password'; $count=mysqli_num_rows($res); if($count1){ header('location: members/index.php'); $fmsg='User does not exist'; |
2 4 6 | if(filter_var($username,FILTER_VALIDATE_EMAIL)){ }else{ } |
2 4 6 | if(filter_var($username,FILTER_VALIDATE_EMAIL)){ }else{ } |
2 4 6 8 10 12 14 16 18 20 | $username=mysqli_real_escape_string($connection,$_POST['username']); $sql='SELECT * FROM `user` WHERE '; $sql.='email='$username'; $sql.='username='$username'; $sql.=' AND password='$password' AND active=1'; $res=mysqli_query($connection,$sql); $_SESSION['username']=$username; }else{ } |