Advertisement
Guest User

login

a guest
Jul 10th, 2016
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. <?php
  2. session_start();
  3. class Crud {
  4. private $conn;
  5. public function __construct($host,$user,$pass,$db) {
  6. $this->conn=mysqli_connect($host,$user,$pass,$db);
  7.  
  8. if(mysqli_connect_errno()){
  9. die("Connection error ".mysqli_connect_error());
  10. }
  11. }
  12.  
  13. public function Login($table, $username, $password) {
  14. $password = sha1($password);
  15. $sql="SELECT * FROM $table WHERE username='$username' AND password = '$password'";
  16.  
  17. $query= mysqli_query($this->conn,$sql);
  18.  
  19. if(mysqli_num_rows($query)==1){
  20.  
  21. $rows=mysqli_fetch_assoc($query);
  22. $_SESSION['username']=$rows['username'];
  23. $_SESSION['logged_in'] = TRUE;
  24. $_SESSION['firstname'] = $rows['firstname'];
  25. $_SESSION['lastname'] = $rows['lastname'];
  26. return true;
  27. }
  28.  
  29. else {
  30. return false;
  31. }
  32. }
  33. }
  34. $obj = new Crud("localhost","root","","webprojekti");
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement