Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- include("models/db.php");
- include("controllers/Users.php");
- echo ("memory limit: " . ini_get("memory_limit") . "<br />");
- echo ("memory usage: " . round(memory_get_usage(true)/1048576,2) . "Mb (" .
- memory_get_usage(true) . " bytes)<br />");
- if(($_SERVER['REQUEST_METHOD'] == 'POST') && isset($_POST["signin"])){
- $object2 = new Users;
- $object2->login($_POST["username"],$_POST["password"]);
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Login</title>
- <?php include("includes/inc.style.php")?>
- </head>
- <body>
- <div class="container">
- <div class="row login-form-wrapper">
- <form class="login-form" action="" method="post" >
- <div class="form-group"><label for="username">Логин</label><input class="form-control" id="username" type="text" name="username"></div>
- <div class="form-group"><label for="password">Пароль</label><input class="form-control" id="password" type="password" name="password"></div>
- <input class="form-control btn btn-primary" type="submit" name ="signin" value="Войти">
- <a href="signupform.php">Dign up</a>
- </form>
- </div>
- </div>
- </body>
- <?php
- class Users extends DB{
- function set($username , $password , $email){
- return $this->insert($username , $password , $email);
- }
- function login($username , $password){
- return $this->login($username , $password );
- }
- }
- <?php
- class DB{
- var $conn;
- function __construct(){
- $this->conn=new mysqli("localhost","root","","Blog");
- if($this->conn->connect_error){
- echo "DB connection error" . $this->conn->connect_error;
- }
- else{
- echo "Connected to db succesfully";
- }
- }
- function login($username , $password){
- echo memory_get_usage();
- $sql="SELECT * from users where username='$username' and password='$password'" ;
- $result=$this->conn->query($sql);
- if ($result->num_rows > 0) {
- while($row = $result->fetch_assoc()) {
- $_SESSION["username"]=$row["username"];
- }
- echo "Success"; //header('Location: post_publication.php');
- } else {
- echo "Не удалось . Ошибка" .$this->conn->error;
- }
- $this->conn->close();
- }
- function insert($username , $password , $email){
- $result=$this->conn->query("INSERT INTO users VALUES('','$username','$password','$email','2')");
- if ($result === TRUE) {
- header('Location: login.php?registered=true');
- }
- else{
- $error= "Не удалось . Ошибка" .$this->conn->error;
- }
- $this->conn->close();
- }
- function __destruct(){
- if ($this->conn!==null) { $this->conn = null; }
- }
- }
- //function login($username , $password){
- // return $this->login($username , $password );
- //}
- return parent::login($username, $password);
Add Comment
Please, Sign In to add comment