· 9 years ago · Dec 14, 2016, 09:32 AM
1<?php
2
3session_start();
4
5$connect = mysql_connect('localhost', 'root', '') or die(mysql_error());
6mysql_select_db('register') or die("Invalid DB((");
7
8//региÑтрациÑ
9if(isset($_POST['submit_login'])) {
10 $login = $_POST['login'];
11 $password = $_POST['password'];
12 $key = $_POST['key'];
13
14 $query_check = mysql_query("SELECT id FROM user WHERE login = '$login'"); // проверка на дубль
15 $row_check = mysql_fetch_array($query_check);
16 if(!empty($row_check['id'])) {
17 echo "дубль";
18 }
19
20 $sql = mysql_query("INSERT INTO user VALUES('', '$login', '$password', '$key')") or die("что то пошло не так"); //добавление Ð¿Ð¾Ð»ÑŒÐ·Ð¾Ð²Ð°Ñ‚ÐµÐ»Ñ Ð² бд
21}
22
23//авторизациÑ
24if(isset($_POST['submit_auth'])) {
25 $login_auth = $_POST['login_auth'];
26 $password_auth = $_POST['password_auth'];
27
28 $query_auth = mysql_query("SELECT id FROM user WHERE login = '$login_auth' AND password = '$password_auth'");// проверка логина и паролÑ
29 $row = mysql_num_rows($query_auth);
30 if($row > 0) {
31 $_SESSION['login'] = $login_auth;
32 }
33 else {
34 echo "login or password mist match";
35 }
36
37}
38
39if(isset($_POST['logout_btn'])) { //logout
40 unset($_SESSION['login']);
41 session_destroy();
42}
43
44if(isset($_POST['submit_forgot'])) { //воÑтановление паролÑ
45 $login_forgot = $_POST['login_forgot'];
46 $key_forgot = $_POST['key_forgot'];
47
48$sql_forgot = mysql_query("SELECT id FROM user WHERE login = '$login_forgot' AND secret_key = '$key_forgot'");
49$row_forgot = mysql_num_rows($sql_forgot);
50//$myrow = mysql_fetch_array($sql_forgot);
51if($row_forgot > 0) {
52 echo "succes";
53}
54else {
55 echo "bad";
56}
57}
58?>
59
60<html>
61 <head>
62 <title>Login</title>
63 <meta charset="utf-8">
64 </head>
65 <body>
66 <h1>РегиÑтрациÑ</h1>
67 <form method="post" action="index.php">
68 <input type="text" name="login" required="" placeholder="login">
69 <input type="password" name="password" required="" placeholder="password">
70 <input type="text" name="key" required="" placeholder="secret key">
71 <input type="submit" name="submit_login" value="Go">
72 </form>
73 <hr>
74 <h1>ВоÑтановление паролÑ</h1>
75 <form method="post" action="index.php" >
76 <input type="text" name="login_forgot" required="" placeholder="login">
77 <input type="text" name="key_forgot" required="" placeholder="secret key">
78 <input type="submit" name="submit_forgot" value="GO">
79 </form>
80 <hr>
81 <?php
82 if(isset($_SESSION['login'])) {
83 echo '<span>Привет, </span>';
84 echo $_SESSION['login'];
85 echo '<form method="post" action="index.php">
86 <input type="submit" name="logout_btn" value="logout">
87 </form>';
88
89 }
90 else {
91 echo '<h1>ÐвторизациÑ</h1>
92 <form method="post" action="index.php">
93 <input type="text" name="login_auth" placeholder="login" required="">
94 <input type="password" name="password_auth" placeholder="password" required="">
95 <input type="submit" name="submit_auth" value="GO">
96 </form>';
97 }
98 ?>
99 </body>
100</html>