Created
September 16, 2018 18:24
-
-
Save corocoto/7299d491bfb79b5737ec73c45013c68c to your computer and use it in GitHub Desktop.
Простая авторизация (без регистрации)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Document</title> | |
</head> | |
<body> | |
<p>Логин: <input type="text" id="login"></p> | |
<p>Пароль: <input type="text" id="password"></p> | |
<button>Отправить</button> | |
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(document).ready(function() { | |
$('button').on('click', function (argument) { | |
$.post( | |
"login.php", | |
{ | |
"login" : $('#login').val(), | |
"password" : $('#password').val() | |
}, | |
function (data){ | |
$(location).attr('href','main.php') | |
}) | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$login=$_POST['login']; | |
$password =$_POST['password']; | |
$login= trim($login); | |
$password = trim($password); | |
if ($login=='tema' AND $password=='12345') { | |
setcookie('log', 'tema', time()+3600); | |
echo 1; | |
}else{ | |
setcookie('log', '', time()-3600); | |
echo 0; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (isset($_COOKIE['log']) AND $_COOKIE['log']!='') { | |
echo 'Добро пожаловать '.$_COOKIE['log'] ; | |
}else{ | |
echo 'Вы ввели неправильный логин или пароль' ; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment