- Автор темы
- #1
PHP:
session_start();
if ($_POST['loginout']) {
setcookie("login", "", time()-36000);
setcookie("password", "", time()-36000);
session_destroy();
Header("Location: ".$_SERVER['HTTP_REFERER']);
}
if ($_POST['login']!='' && $_POST['password']!='' && $_SESSION['grant'] != 1) {
$login = pg_escape_string($_POST['login']);
$password = pg_escape_string(md5(md5($_POST['password'])));
$result = pg_query($db, "SELECT user_id FROM people where user_name='".$login."' and user_pass='".$password."'");
if ($result) {
$row = pg_fetch_row($result);
$_SESSION['grant'] = 1;
$_SESSION['login'] = $login;
setcookie("login", $login, time() + 36000,"/", $_SERVER['SERVER_NAME'], 0);
setcookie("password", $password, time() + 36000,"/", $_SERVER['SERVER_NAME'], 0);
Header("Location: ".$_SERVER['HTTP_REFERER']);
}
}
if ($_SESSION['grant']!=1) {
if (isset($_COOKIE['login']) && isset($_COOKIE['password'])) {
$login = pg_escape_string($_COOKIE['login']);
$password = pg_escape_string($_COOKIE['password']);
$result = pg_query($db, "SELECT user_id FROM people where user_name='".$login."' and user_pass='".$password."'");
if ($result) {
$row = pg_fetch_row($result);
$_SESSION['grant'] = 1;
$_SESSION['login'] = $login;
}
}
}
if ($_SESSION['grant'] == 1){
echo "<form action=index.php?loginout=ok method=post name=au><input type=submit value=Выйти name=loginout>";
}else {
echo "<form action=index.php method=POST name=au>Name:<input type=text name=login maxlenght=20>";
echo "Pass:<input type=password name=password maxlenght=16 size=12>";
echo "<input type=submit value=Войти name=sub> ";
echo "<a href=index.php?act=1>Регистрация</a><hr noshade></form>";
}