Advertisement
Guest User

Untitled

a guest
Aug 15th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.27 KB | None | 0 0
  1. <?php
  2.  
  3. /******************************************************
  4.  *
  5.  *      users.php                       by @visualidiot
  6.  *
  7.  ******************************************************
  8.  *
  9.  *      Retrieve information about users
  10.  */
  11.  
  12. class User() {
  13.   public  $username = '';
  14.   private $password = '';
  15.  
  16.   function __construct($username = '', $password = '') {
  17.     $this->username = $username;
  18.     $this->password = $password;
  19.   }
  20.  
  21.   function isLoggedIn() {
  22.     return (isset($_SESSION['username']) || isset($_COOKIE['username']));
  23.   }
  24.  
  25.   function exists() {
  26.     //  I'll rewrite this with PDO at some point.
  27.     //  For now, though, it's just good old MySQL.
  28.     include('paths.php');
  29.     include($path . '/config/database.php');
  30.     $link = @mysql_connect($host, $user, $pass);
  31.     @mysql_select_db($name);
  32.    
  33.     return @mysql_num_rows(@mysql_query("SELECT * FROM `users` WHERE `username` = '$this->username'", $link));
  34.   }
  35. }
  36.  
  37. // Usage
  38. $connor = new User('Connor', 'his_password'); // This would hold all of his user information
  39.  
  40. $nonExistant = new User('randomfag');
  41. echo 'Randomfag does ' . (($nonExistant->exists() === true) ? '' : 'not ') . 'exist';
  42.  
  43. $currentUser = new User();
  44. echo 'You are ' . (($currentUser->isLoggedIn() === true) ? '' : 'not ') . 'logged in';
  45.  
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement