Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- $connect = mysql_connect('localhost', '', '') or die (mysql_error());
- mysql_select_db('dopdb');
- if(isset($_POST['submit'])){
- $username = $_POST['username'];
- $login = $_POST['login'];
- $password = $_POST['password'];
- $r_password = $_POST['r_password'];
- if($password == $r_password){
- $password = md5($password);
- $query = mysql_query("INSERT INTO users VALUES ('','$username','$login','$password')") or die (mysql_error());
- }
- else{
- die("Passwords doesn't match.");
- }
- }
- if(isset($_POST['enter'])){
- $e_login = $_POST['e_login'];
- $e_password = md5($_POST['e_password']);
- $query = mysql_query("SELECT '' FROM users WHERE login = $e_login");
- $user_data = mysql_fetch_array($query);
- if($user_data['password'] == $e_password){
- session_start();
- $_SESSION['your_session'] = $e_login;
- }
- else{
- echo 'Wrong password!';
- }
- }
- if(isset($_POST['logout'])){
- unset($_SESSION['your_session']);
- session_destroy();
- }
- ?>
- <!doctype html>
- <html lang="ru">
- <head>
- <title>PHP&MySQL</title>
- <meta charset="windows-1251">
- <link rel="stylesheet" type="text/css" href="style.css" />
- </head>
- <body id="body">
- <div id="header">
- <span id="greet">Test Site</span>
- <span class="urls">
- <a href="index.php" >Главная</a>
- <a href="page1.php" >Страница 1</a>
- <a href="page2.php" >Страница 2</a>
- <a href="registration.php">Регистрация</a>
- </span>
- </div>
- <?php
- if(isset($_SESSION['your_session'])){
- $login_check = true;
- echo '<p style = "font-size:36, color: blue;" >Добро пожаловать!</p><br>
- <form method="post" action="index.php">
- <input class="submit" type="submit" name="logout" value="Выйти">
- </form>
- ';
- }
- else{
- echo '<form id="login_form" action="/" method="post">
- <label>Логин</label><br>
- <input class="form_input" type="text" name="e_login" required /><br>
- <label>Пароль</label><br>
- <input class="form_input" type="password" name="e_password" required /><br>
- <input class="submit" type="submit" name="enter" value="Отправить"/>
- </form>';
- }
- ?>
- </body>
- <footer id="footer">
- <b id="basement">Footer</b>
- </footer>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement