Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. <?php
  2. class Connection {
  3. private $host = "localhost";
  4. private $user = "root";
  5. private $dbname = "mydb";
  6. private $pass = "";
  7. protected $db;
  8.  
  9. public function Connection()
  10. {
  11. try
  12. {
  13. $this->conn = new PDO("mysql:host=".$this-> host.";dbname=".$this-> dbname, $this-> user, $this-> pass);
  14. $this-> conn-> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  15. }
  16. catch(PDOException $e)
  17. {
  18. echo 'ERROR: '.$e->getMessage();
  19. }
  20. $this->db=$this->conn;
  21. }
  22.  
  23. function disconnect()
  24. {
  25. $this->disconnect();
  26. }
  27. }
  28. ?>
  29.  
  30. <?php
  31. include ("connection.php");
  32. class baseController{
  33. public function __construct() {
  34. $this->db=new Connection();
  35. define('BASE_PATH', $_SERVER["HTTP_HOST"]."/live/mysite/");
  36. }
  37. }
  38. ?>
  39.  
  40. <?php
  41. class userclass {
  42. function _construct()
  43. {
  44. $this->db=new Connection();
  45. }
  46. public function login($tablename,$usernamefld,$userpswdfield,$usrname,$passwrd)
  47. {
  48. try
  49. {
  50. $stmt=$this->db->prepare("select * from $tablename where BINARY $usernamefld =:uname and BINARY $userpswdfield =:authnme and permission='0' and delet='0'");
  51. $stmt->execute(array(':uname'=>$usrname,':authnme'=>$passwrd));
  52. $userRow = $stmt->fetch(PDO::FETCH_ASSOC);
  53. if($stmt->rowCount()>0)
  54. {
  55. $_SESSION['user_session'] = $usrname;
  56. return true;
  57. }
  58. }
  59. catch(PDOException $e)
  60. {
  61. echo 'ERROR: '.$e->getMessage();
  62. }
  63. }
  64. public function loggedin()
  65. {
  66. if(isset($_SESSION['user_session']))
  67. {
  68. return true;
  69. }
  70. }
  71. }
  72. $clas = new userclass();
  73. ?>
  74.  
  75. <?php
  76. include_once("baseController.php");
  77. include 'database.php';
  78. $file = basename($_SERVER["PHP_SELF"],".php");
  79. $className = $file."Controller";
  80. $controller = "controller/".$file."Controller.php";
  81. if(file_exists($controller))
  82. {
  83. include($controller);
  84. $obj = new $className();
  85. }
  86. ?>
  87.  
  88. <?php
  89. session_start();
  90. class indexController extends baseController{
  91. function __construct() {
  92. parent::__construct();
  93. $this->title="Home";
  94. if(isset($_POST["login"])){
  95. $this->login();
  96. }
  97. }
  98. public function login()
  99. {
  100. extract($_POST);
  101. if($this->$clas->login('users','user_name','password',$usname,$uspswd))
  102. {
  103. $this->$clas->redirect("BASE_PATH/../pages/home");
  104. }
  105. else
  106. {
  107. $this->errormsg = "Username or Password Incorrect";
  108. $error=false;
  109. }
  110. }
  111. }
  112. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement