Advertisement
Guest User

Clases.kernel.php

a guest
Aug 24th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. * Copyright (C) 2013 Finley Siebert
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19.  
  20. class Habbo {
  21. public function database($h, $u, $p, $db){
  22. $this->conn = new mysqli($h,$u,$p,$db); // So i don't have to use global.
  23. }
  24. public function url($url){
  25. $this->url = $url;
  26. return $this->url;
  27. }
  28. public function checkData($un, $pw) {
  29.  
  30. $this->query = $this->conn->query("SELECT * FROM users WHERE username = '$un' AND password = '$pw'");
  31. if($this->query->num_rows == 1) {
  32. $_SESSION['id'] = $un;
  33. header('location: '. $this->url .'me');
  34. $ip = $_SERVER['REMOTE_ADDR'];
  35. $this->conn->query("UPDATE users SET ip_last = '$ip' WHERE username = '$un'");
  36. } else {
  37. echo "<div class='message error'>Wrong credintials</div>";
  38. }
  39. }
  40.  
  41. public function generateTicket(){
  42. $this->sessionKey = 'ST-'.rand(9,999).'-'.substr(sha1(time()).'-'.rand(9,9999999).'-'.rand(9,9999999).'-'.rand(9,9999999),0,33);
  43. return $this->sessionKey;
  44. }
  45.  
  46. public function registerUser($username, $password, $email, $ticket){
  47. $db_errors = array();
  48.  
  49. $this->query = $this->conn->query("SELECT * FROM users WHERE username = '$username'");
  50. if($this->query->num_rows == 1){
  51. $db_errors[] = '<div class="error message">Username already in use</div>';
  52. }
  53. $this->check_email = $this->conn->query("SELECT * FROM users WHERE email = '$email'");
  54. if($this->check_mail->num_rows == 1 ){
  55. $db_errors[] = '<div class="error message"> Email already in use </div>';
  56. }
  57. foreach($db_errors as $db_e){
  58. echo '<div class="error message">'. $db_e .'</div>';
  59. }
  60.  
  61. if(count($db_errors) == 0){
  62. $ip = $_SERVER['REMOTE_ADDR'];
  63. $this->conn->query("INSERT INTO users(username, password, mail, auth_ticket,look,motto,ip_reg) VALUES('$username', '$password', '$email', '$ticket', 'hr-115-42.hd-190-1.ch-215-62.lg-285-91.sh-290-62', 'Welcome to Habbo!','$ip')");
  64. $_SESSION['id'] = $username;
  65. header('location: '. $this->url .'me');
  66. }
  67. }
  68.  
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement