Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $db = mysqli_connect ('localhost', 'root', '', 'base');
- if (!isset($_COOKIE['user_id'])){
- if(isset($_POST['submit'])){
- $user_username = mysqli_real_escape_string($db, trim($_POST['username']));
- $user_password = mysqli_real_escape_string($db, trim($_POST['password']));
- if(!empty($user_username) && !empty($user_password)){
- $query = ("SELECT `user_id` , `username` FROM `signup` WHERE username = '$user_username' AND password = '$user_password'");
- $data = mysqli_query ($db, $query);
- if (mysqli_num_rows($data) == 1) {
- $row = mysqli_fetch_assoc($data);
- setcookie('password', $row['password'],time() + (60*60*24*30));
- setcookie('username', $row['username'],time() + (60*60*24*30));
- $home_url = 'http://' . $_SERVER['HTTP_HOST'];
- header("Location: /home.php");exit;
- }
- else{
- echo 'нет пользователя';
- }
- }
- else{
- echo'заполните все поля';
- }
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- </head>
- <body>
- <?php
- if(empty($_COOKIE['username'])) {
- ?>
- <section>
- <form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
- <p>Авторизация</pre> <a href = 'home.php'>Регистрация</a><br>
- <label for='username'>Логин</label>
- <input type = "text" name= "username" ><br>
- <label for='password'>Пароль</label>
- <input type = "text" name="password" ><br>
- <input type="submit" name ="submit" value = 'готово'><br>
- </form>
- <?php
- }
- else{
- ?>
- <p> Мой профиль </p>
- <p> Выйти</p>
- <?php
- }
- ?>
- </section>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement