Skip to content

Instantly share code, notes, and snippets.

@corocoto
Created September 16, 2018 18:24
Show Gist options
  • Save corocoto/7299d491bfb79b5737ec73c45013c68c to your computer and use it in GitHub Desktop.
Save corocoto/7299d491bfb79b5737ec73c45013c68c to your computer and use it in GitHub Desktop.
Простая авторизация (без регистрации)
<!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>
<?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;
}
?>
<?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