Guest User

Untitled

a guest
Nov 26th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. <?php
  2. session_start();
  3. include("models/db.php");
  4. include("controllers/Users.php");
  5. echo ("memory limit: " . ini_get("memory_limit") . "<br />");
  6. echo ("memory usage: " . round(memory_get_usage(true)/1048576,2) . "Mb (" .
  7. memory_get_usage(true) . " bytes)<br />");
  8.  
  9.  
  10. if(($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST["signin"])){
  11.  
  12. $object2 = new Users;
  13. $object2->login($_POST["username"],$_POST["password"]);
  14.  
  15. }
  16.  
  17. ?>
  18.  
  19. <!DOCTYPE html>
  20. <html>
  21. <head>
  22. <title>Login</title>
  23. <?php include("includes/inc.style.php")?>
  24. </head>
  25. <body>
  26. <div class="container">
  27. <div class="row login-form-wrapper">
  28. <form class="login-form" action="" method="post" >
  29. <div class="form-group"><label for="username">Логин</label><input class="form-control" id="username" type="text" name="username"></div>
  30. <div class="form-group"><label for="password">Пароль</label><input class="form-control" id="password" type="password" name="password"></div>
  31. <input class="form-control btn btn-primary" type="submit" name ="signin" value="Войти">
  32. <a href="signupform.php">Dign up</a>
  33. </form>
  34. </div>
  35. </div>
  36. </body>
  37.  
  38. <?php
  39. class Users extends DB{
  40. function set($username , $password , $email){
  41. return $this->insert($username , $password , $email);
  42. }
  43. function login($username , $password){
  44. return $this->login($username , $password );
  45. }
  46. }
  47.  
  48. <?php
  49. class DB{
  50. var $conn;
  51.  
  52. function __construct(){
  53. $this->conn=new mysqli("localhost","root","","Blog");
  54. if($this->conn->connect_error){
  55. echo "DB connection error" . $this->conn->connect_error;
  56. }
  57. else{
  58. echo "Connected to db succesfully";
  59. }
  60. }
  61.  
  62. function login($username , $password){
  63. echo memory_get_usage();
  64. $sql="SELECT * from users where username='$username' and password='$password'" ;
  65. $result=$this->conn->query($sql);
  66. if ($result->num_rows > 0) {
  67. while($row = $result->fetch_assoc()) {
  68. $_SESSION["username"]=$row["username"];
  69. }
  70. echo "Success"; //header('Location: post_publication.php');
  71. } else {
  72. echo "Не удалось . Ошибка" .$this->conn->error;
  73. }
  74.  
  75.  
  76. $this->conn->close();
  77. }
  78. function insert($username , $password , $email){
  79. $result=$this->conn->query("INSERT INTO users VALUES('','$username','$password','$email','2')");
  80.  
  81. if ($result === TRUE) {
  82. header('Location: login.php?registered=true');
  83. }
  84. else{
  85. $error= "Не удалось . Ошибка" .$this->conn->error;
  86. }
  87. $this->conn->close();
  88. }
  89. function __destruct(){
  90. if ($this->conn!==null) { $this->conn = null; }
  91. }
  92.  
  93.  
  94.  
  95.  
  96. }
  97.  
  98. //function login($username , $password){
  99. // return $this->login($username , $password );
  100. //}
  101.  
  102. return parent::login($username, $password);
Add Comment
Please, Sign In to add comment