Advertisement
Guest User

Untitled

a guest
May 6th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <?php
  2. $db = mysqli_connect ('localhost', 'root', '', 'base');
  3.  
  4. if (!isset($_COOKIE['user_id'])){
  5. if(isset($_POST['submit'])){
  6. $user_username = mysqli_real_escape_string($db, trim($_POST['username']));
  7. $user_password = mysqli_real_escape_string($db, trim($_POST['password']));
  8. if(!empty($user_username) && !empty($user_password)){
  9. $query = ("SELECT `user_id` , `username` FROM `signup` WHERE username = '$user_username' AND password = '$user_password'");
  10. $data = mysqli_query ($db, $query);
  11. if (mysqli_num_rows($data) == 1) {
  12.  
  13. $row = mysqli_fetch_assoc($data);
  14. setcookie('password', $row['password'],time() + (60*60*24*30));
  15. setcookie('username', $row['username'],time() + (60*60*24*30));
  16. $home_url = 'http://' . $_SERVER['HTTP_HOST'];
  17. header("Location: /home.php");exit;
  18.  
  19.  
  20.  
  21. }
  22.  
  23. else{
  24. echo 'нет пользователя';
  25. }
  26. }
  27. else{
  28. echo'заполните все поля';
  29. }
  30. }
  31. }
  32. ?>
  33. <!DOCTYPE html>
  34. <html>
  35. <head>
  36. <meta charset="utf-8">
  37. <title></title>
  38.  
  39. </head>
  40. <body>
  41.  
  42. <?php
  43. if(empty($_COOKIE['username'])) {
  44. ?>
  45. <section>
  46. <form method="POST" action="<?php echo $_SERVER['PHP_SELF'];?>">
  47. <p>Авторизация</pre> <a href = 'home.php'>Регистрация</a><br>
  48. <label for='username'>Логин</label>
  49. <input type = "text" name= "username" ><br>
  50. <label for='password'>Пароль</label>
  51. <input type = "text" name="password" ><br>
  52. <input type="submit" name ="submit" value = 'готово'><br>
  53. </form>
  54. <?php
  55. }
  56. else{
  57.  
  58. ?>
  59. <p> Мой профиль </p>
  60. <p> Выйти</p>
  61. <?php
  62. }
  63.  
  64. ?>
  65. </section>
  66. </body>
  67. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement