Tagged: php dashboard source code

Vue.js Simple Login Script using PHP MySQLi Bootstrap 0

Vue.js Simple Login Script using PHP MySQLi Bootstrap

Vue.js Simple Login Script using PHP MySQLi Bootstrap

In this Post We Will Explain About is Vue.js Simple Login with PHP/MySQLi With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to simple login page using Vue.js Example

In this post we will show you Best way to implement simple session with Vue.js and php, hear for Vue.js Login Script using PHP MySQL Bootstrap with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Creating our Database

CREATE TABLE `usermst` (
  `uID` INT(11) NOT NULL AUTO_INCREMENT,
  `uFirstName` VARCHAR(30) NOT NULL,
  `password` VARCHAR(30) NOT NULL,
PRIMARY KEY(`uID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Inserting Data into our Database

INSERT INTO `usermst` (`uID`, `uFirstName`, `password`) VALUES
(1, 'jaydeep', 'Gondaliya'),
(2, 'ankit', 'kathiriya');

index.php

<?php
	session_start();
	if(isset($_SESSION['usermst'])){
		header('location:success.php');
	}
?>
<!DOCTYPE html>
<html>
<head>
	<title>Simple Example of Vue.js Login with PHP and MySQLi</title>
	<link rel="stylesheet" href="<a href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="live container">
	<h1 class="page-header text-center">Simple Example of the Vue.js Login with PHP and MySQLi</h1>
	<div id="login">
		<div class="col-xl-4 col-xl-offset-4">
 
			<div class="panel panel-success">
			  	<div class="panel-heading"><span class="live glyphicon glyphicon-lock"></span> Log in</div>
			  	<div class="panel-body">
			    	<label>UserFirstName:</label>
			    	<input type="text" class="form-control" v-model="userDetails.uFirstName" v-on:keyup="allKeyMonitor">
			    	<label>Password:</label>
			    	<input type="password" class="form-control" v-model="userDetails.password" v-on:keyup="allKeyMonitor">
			  	</div>
			  	<div class="panel-footer">
			  		<button class="btn btn-success btn-block" @click="checkLogin();"><span class="live glyphicon glyphicon-log-in"></span> Login</button>
			  	</div>
			</div>
 
			<div class="live alert alert-danger text text-center" v-if="msgError">
				<button type="button" class="close" @click="dataClearMsg();"><span aria-hidden="true">×</span></button>
				<span class="live glyphicon glyphicon-alert"></span> {{ msgError }}
			</div>
 
			<div class="alert alert-success text-center" v-if="msgSuccess">
				<button type="button" class="close" @click="dataClearMsg();"><span aria-hidden="true">×</span></button>
				<span class="glyphicon glyphicon-check"></span> {{ msgSuccess }}
			</div>
 
		</div>
	</div>
</div>
<script src="vue.js"></script>
<script src="axios.js"></script>
<script src="main.js"></script>
</body>
</html>

main.js

var main = new Vue({
	el: '#login',
	data:{
		msgSuccess: "",
		msgError: "",
		userDetails: {uFirstName: '', password: ''},
	},
 
	methods:{
		allKeyMonitor: function(event) {
       		if(event.key == "Enter"){
         		main.checkLogin();
        	}
       	},
 
		checkLogin: function(){
			var logForm = main.toFormData(main.userDetails);
			axios.post('login.php', logForm)
				.then(function(dataRes){
 
					if(dataRes.data.error){
						main.msgError = dataRes.data.message;
					}
					else{
						main.msgSuccess = dataRes.data.message;
						main.userDetails = {uFirstName: '', password:''};
						setTimeout(function(){
							window.location.href="success.php";
						},2000);
 
					}
				});
		},
 
		toFormData: function(obj){
			var form_data = new FormData();
			for(var key in obj){
				form_data.append(key, obj[key]);
			}
			return form_data;
		},
 
		dataClearMsg: function(){
			main.msgError = '';
			main.msgSuccess = '';
		}
 
	}
});

login.php

<?php
session_start();
 
$db_con = new mysqli("localhost", "username", "YourPassword", "atmiya");
 
if ($db_con->connect_error) {
    die("Connection failed: " . $db_con->connect_error);
}
 
$res_Output = array('error' => false);
 
$uFirstName = $_POST['uFirstName'];
$password = $_POST['password'];
 
if($uFirstName==''){
	$res_Output['error'] = true;
	$res_Output['message'] = "UserFirstName is required";
}
else if($password==''){
	$res_Output['error'] = true;
	$res_Output['message'] = "Your Password is required";
}
else{
	$sql = "select * from usermst where uFirstName='$uFirstName' and password='$password'";
	$query = $db_con->query($sql);
 
	if($query->num_rows>0){
		$row=$query->fetch_array();
		$_SESSION['usermst']=$row['uID'];
		$res_Output['message'] = "Login Successful";
	}
	else{
		$res_Output['error'] = true;
		$res_Output['message'] = "User Login Failed. User not Found";
	}
}
 
 
 
$db_con->close();
 
header("Content-type: application/json");
echo json_encode($res_Output);
die();
 
 
?>

success.php

<?php
	session_start();
	$db_con = new mysqli("localhost", "username", "yourpassword", "atmiya");
 
	if ($db_con->connect_error) {
	    die("Connection failed: " . $db_con->connect_error);
	}
 
	if (!isset($_SESSION['usermst']) ||(trim ($_SESSION['usermst']) == '')){
		header('location:index.php');
	}
 
	$sql="select * from usermst where uID='".$_SESSION['usermst']."'";
	$query=$db_con->query($sql);
	$row=$query->fetch_array();
 
?>
<!DOCTYPE html>
<html>
<head>
	<title>Example of the Vue.js Login with PHP as well as MySQLi demo</title>
	<link rel="stylesheet" href="<a href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
	<div class="container">
		<div class="live jumbotron">
			<h1 class="text-center">You are most Welcome, <?php echo $row['uFirstName']; ?>!</h1>
			<a href="logout.php" class="btn btn-success"><span class="live glyphicon glyphicon-log-res_Output"></span> Logout</a>
		</div>
	</div>
</body>
</html>

logout.php

<?php
	session_start();
	session_destroy();
	header('location:index.php');
?>

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is Vue.js Simple Login with PHP/MySQLi And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.