Advertisement
Guest User

Untitled

a guest
Aug 31st, 2016
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4.  
  5. $connect = mysql_connect('localhost', '', '') or die (mysql_error());
  6. mysql_select_db('dopdb');
  7.  
  8. if(isset($_POST['submit'])){
  9. $username = $_POST['username'];
  10. $login = $_POST['login'];
  11. $password = $_POST['password'];
  12. $r_password = $_POST['r_password'];
  13. if($password == $r_password){
  14. $password = md5($password);
  15. $query = mysql_query("INSERT INTO users VALUES ('','$username','$login','$password')") or die (mysql_error());
  16. }
  17. else{
  18. die("Passwords doesn't match.");
  19. }
  20. }
  21. if(isset($_POST['enter'])){
  22. $e_login = $_POST['e_login'];
  23. $e_password = md5($_POST['e_password']);
  24.  
  25. $query = mysql_query("SELECT '' FROM users WHERE login = $e_login");
  26. $user_data = mysql_fetch_array($query);
  27.  
  28.  
  29. if($user_data['password'] == $e_password){
  30. session_start();
  31. $_SESSION['your_session'] = $e_login;
  32. }
  33. else{
  34. echo 'Wrong password!';
  35. }
  36. }
  37. if(isset($_POST['logout'])){
  38. unset($_SESSION['your_session']);
  39. session_destroy();
  40. }
  41. ?>
  42.  
  43. <!doctype html>
  44. <html lang="ru">
  45. <head>
  46. <title>PHP&MySQL</title>
  47. <meta charset="windows-1251">
  48. <link rel="stylesheet" type="text/css" href="style.css" />
  49. </head>
  50. <body id="body">
  51. <div id="header">
  52. <span id="greet">Test Site</span>
  53. <span class="urls">
  54. <a href="index.php" >Главная</a>
  55. <a href="page1.php" >Страница 1</a>
  56. <a href="page2.php" >Страница 2</a>
  57. <a href="registration.php">Регистрация</a>
  58. </span>
  59. </div>
  60. <?php
  61. if(isset($_SESSION['your_session'])){
  62. $login_check = true;
  63. echo '<p style = "font-size:36, color: blue;" >Добро пожаловать!</p><br>
  64. <form method="post" action="index.php">
  65. <input class="submit" type="submit" name="logout" value="Выйти">
  66. </form>
  67. ';
  68. }
  69. else{
  70. echo '<form id="login_form" action="/" method="post">
  71. <label>Логин</label><br>
  72. <input class="form_input" type="text" name="e_login" required /><br>
  73. <label>Пароль</label><br>
  74. <input class="form_input" type="password" name="e_password" required /><br>
  75. <input class="submit" type="submit" name="enter" value="Отправить"/>
  76. </form>';
  77. }
  78.  
  79. ?>
  80. </body>
  81. <footer id="footer">
  82. <b id="basement">Footer</b>
  83. </footer>
  84. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement