Доброго времени суток всем.
Столкнулся вот с такой проблемой.
Есть авторизация. Как можно сделать так чтобы в php автоматически подставить данные "логин" и "пароль" чтобы пропустить форму авторизации.
Я хочу сам подставить логин и пароль чтобы пользователь не вводил.
Код формы авторизации:
<?php
include 'init.php';
if($users->isLoggedIn()) {
header('Location: ./');
}
$errorMessage = $users->login();
include('inc/header.php');
?>
<title>webdamn.com : Demo Build Helpdesk System with PHP & MySQL</title>
<?php include('inc/container.php');?>
<div class="container contact">
<h2>Example: Build Helpdesk System with PHP & MySQL</h2>
<div class="col-md-6">
<div class="panel panel-info">
<div class="panel-heading" style="background:#00796B;color:white;">
<div class="panel-title">User Login</div>
</div>
<div style="padding-top:30px" class="panel-body" >
<?php if ($errorMessage != '') { ?>
<div id="login-alert" class="alert alert-danger col-sm-12"><?php echo $errorMessage; ?></div>
<?php } ?>
<form id="loginform" class="form-horizontal" role="form" method="POST" action="">
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-user"></i></span>
<input type="text" class="form-control" id="email" name="email" placeholder="email" style="background:white;" required>
</div>
<div style="margin-bottom: 25px" class="input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-lock"></i></span>
<input type="password" class="form-control" id="password" name="password"placeholder="password" required>
</div>
<div style="margin-top:10px" class="form-group">
<div class="col-sm-12 controls">
<input type="submit" name="login" value="Login" class="btn btn-success">
</div>
</div>
<div style="margin-top:10px" class="form-group">
<div class="col-sm-12 controls">
Admin: admin@webdamn.com<br>
password:123 <br><br>
User: smith@webdamn.com<br>
password:123
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php include('inc/footer.php');?>
Код для проверки правильности введенных данных:
<?php
class Users extends Database {
private $userTable = 'hd_users';
private $dbConnect = false;
public function __construct(){
$this->dbConnect = $this->dbConnect();
}
public function isLoggedIn () {
if(isset($_SESSION["userid"])) {
return true;
} else {
return false;
}
}
public function login(){
$errorMessage = '';
if(!empty($_POST["login"]) && $_POST["email"]!=''&& $_POST["password"]!='') {
$email = $_POST['email'];
$password = $_POST['password'];
$sqlQuery = "SELECT * FROM ".$this->userTable."
WHERE email='".$email."' AND password='".md5($password)."'";
$resultSet = mysqli_query($this->dbConnect, $sqlQuery);
$isValidLogin = mysqli_num_rows($resultSet);
if($isValidLogin){
$userDetails = mysqli_fetch_assoc($resultSet);
$_SESSION["userid"] = $userDetails['id'];
$_SESSION["user_name"] = $userDetails['nick_name'];
if($userDetails['user_group']) {
$_SESSION["admin"] = $userDetails['user_group'];
}
header("location: index.php");
} else {
$errorMessage = "Invalid login!";
}
} else if(!empty($_POST["login"])){
$errorMessage = "Enter Both user and password!";
}
return $errorMessage;
}
public function getUserInfo() {
if(!empty($_SESSION["userid"])) {
$sqlQuery = "SELECT * FROM ".$this->userTable."
WHERE id ='".$_SESSION["userid"]."'";
$result = mysqli_query($this->dbConnect, $sqlQuery);
$userDetails = mysqli_fetch_assoc($result);
return $userDetails;
}
}
public function getColoumn($id, $column) {
$sqlQuery = "SELECT * FROM ".$this->userTable."
WHERE id ='".$id."'";
$result = mysqli_query($this->dbConnect, $sqlQuery);
$userDetails = mysqli_fetch_assoc($result);
return $userDetails[$column];
}
}