Advertisement
Moravetskyi

Untitled

Sep 11th, 2014
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.01 KB | None | 0 0
  1. <?php
  2. $connect = mysqli_connect('localhost', 'root', '12345', 'bugs');
  3. $result = mysqli_query($connect, "Select * from user");
  4.  
  5. if (mysqli_connect_errno()) {
  6. die( "Failed to connect to MySQL: " . mysqli_connect_error());
  7. }
  8.  
  9. //protect from html
  10. $user_login = htmlspecialchars($_POST['login']);
  11. $user_password = htmlspecialchars($_POST['pass']);
  12.  
  13. //protected from sql
  14. $login = mysqli_real_escape_string($connect, stripslashes($user_login));
  15. $password = md5(mysqli_real_escape_string($connect, stripslashes($user_password))).$login;
  16.  
  17. echo "Login: ".$login."<br> Password: ".$password;
  18. //Log IN
  19. if (isset($_POST['login_b'])) {
  20.  
  21. $query = "Select * from user where login='$login' and password='$password'";
  22. $result = mysqli_query($connect, $query);
  23. $myrow = mysqli_fetch_assoc($result);
  24.  
  25.  
  26. if (!empty($myrow)) {
  27. echo "<p align=center>Hello," . $myrow['login'] . "</p>";
  28. } else {
  29. echo "<p align=center>Wrong login: " . $login . " OR Password: " . $user_password . "</p>";
  30. }
  31.  
  32. }
  33.  
  34. //Registration
  35. if (isset($_POST['reg'])) {
  36. mysqli_query($connect, "insert into user (login,password) values ('$login','$password')");
  37. }
  38. mysqli_close($connect);
  39. ?>
  40.  
  41.  
  42.  
  43. <html>
  44. <head>
  45. <title>LogIn</title>
  46. </head>
  47. <body>
  48.  
  49. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  50. <table align="center">
  51. <tr>
  52. <td><b>Login:</b></td>
  53. <td>
  54. <input type='text' name='login'>
  55. </td>
  56. </tr>
  57.  
  58.  
  59. <tr>
  60. <td><b>Password:</b></td>
  61. <td>
  62. <input type='text' name='pass'>
  63. </td>
  64. </tr>
  65.  
  66.  
  67. <tr>
  68. <td align="center" colspan='2'>
  69. <input id="button" name="login_b" style=" width: 110px;height: 50px" type='submit' value="Log In">
  70. <input id="button" name="reg" style="width: 110px;height: 50px" type='submit' value="Registration">
  71. </td>
  72.  
  73. </tr>
  74.  
  75. </table>
  76. </form>
  77. </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement