+ 4
how to make validation login with php?
4 Réponses
+ 7
First create a login form and compare login data submitted in the form with the data in the database if they match redirect them into their page.
Basic script can be like this (with hard coded credentials without database):
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login Form</title>
</head>
<body>
<form action="login.php" method="POST">
<input type="text" name="username">
<input type="password" name="password">
<input type="submit" value="Log In">
</form>
</body>
</html>
<?php
if (isset($_POST['username']) && isset($_POST['password'])) {
$user = $_POST['username'];
$pass = $_POST['password'];
if ($user == "admin"&& $pass = "123") {
echo "Success!";
}
else{
echo "Error!";
}
}
else{
echo "please fill all fields!";
}
?>
save this code as login.php and it works. username is admin and password is 123
+ 3
You can use a POST method on HTML and transfer the form to script, and do inquary on SQL.
+ 2
I suggest you validate your form with Javascript... Use external styling to make your work neat... Good luck!
+ 2
you must look after to send and get data in login page do with POST method because hacker don't can hack you !!!
and code (this code without database) :
HTML:
<form method="post">
<input type="text" name="username" placeholder="Username"/><br/>.
<input type="text" name="password" placeholder="Password"/><br/>
<input type="submit" value="GET" />
</form>
PHP:
<?php
if(isset($_POST['username']) && isset($_POST['password'])) {
if($_POST['username'] == 'user1' && $_POST['password'] == 'pass1'){
//login completed
}else{
//login not completed
}
}else{
echo 'please set all fields!';
}
?>