Advertisement
shinshinta

koneksi

Jun 12th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. <?php
  2. class Database {
  3.     // properti
  4.     private $dbHost="localhost";
  5.     private $dbUser="root";
  6.     private $dbPass="";
  7.     private $dbName="angsuran";
  8.    
  9.  
  10.     // method koneksi mysql
  11.     function connectMySQL() {
  12.         mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
  13.         mysql_select_db($this->dbName) or die ("Database Tidak Ditemukan di Server");
  14.     }
  15. }
  16.  
  17. class User {
  18. // Proses Login
  19.     function cek_login($user, $password) {
  20.         $password = md5($password);
  21.         $result = mysql_query("SELECT * FROM admin WHERE user='$user' AND password='$password'");
  22.         $user_data = mysql_fetch_array($result);
  23.         $no_rows = mysql_num_rows($result);
  24.         if ($no_rows == 1) {
  25.             $_SESSION['login'] = TRUE;
  26.             $_SESSION['id'] = $user_data['id'];
  27.             return TRUE;
  28.         }
  29.         else {
  30.           return FALSE;
  31.         }
  32.     }
  33.    
  34.     // Ambil Sesi
  35.     function get_sesi() {
  36.         return $_SESSION['login'];
  37.     }
  38.    
  39.     // Logout
  40.     function user_logout() {
  41.         $_SESSION['login'] = FALSE;
  42.         session_destroy();
  43.     }
  44. }
  45.  
  46. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement