Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Connection {
- private $host = "localhost";
- private $user = "root";
- private $dbname = "mydb";
- private $pass = "";
- protected $db;
- public function Connection()
- {
- try
- {
- $this->conn = new PDO("mysql:host=".$this-> host.";dbname=".$this-> dbname, $this-> user, $this-> pass);
- $this-> conn-> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch(PDOException $e)
- {
- echo 'ERROR: '.$e->getMessage();
- }
- $this->db=$this->conn;
- }
- function disconnect()
- {
- $this->disconnect();
- }
- }
- ?>
- <?php
- include ("connection.php");
- class baseController{
- public function __construct() {
- $this->db=new Connection();
- define('BASE_PATH', $_SERVER["HTTP_HOST"]."/live/mysite/");
- }
- }
- ?>
- <?php
- class userclass {
- function _construct()
- {
- $this->db=new Connection();
- }
- public function login($tablename,$usernamefld,$userpswdfield,$usrname,$passwrd)
- {
- try
- {
- $stmt=$this->db->prepare("select * from $tablename where BINARY $usernamefld =:uname and BINARY $userpswdfield =:authnme and permission='0' and delet='0'");
- $stmt->execute(array(':uname'=>$usrname,':authnme'=>$passwrd));
- $userRow = $stmt->fetch(PDO::FETCH_ASSOC);
- if($stmt->rowCount()>0)
- {
- $_SESSION['user_session'] = $usrname;
- return true;
- }
- }
- catch(PDOException $e)
- {
- echo 'ERROR: '.$e->getMessage();
- }
- }
- public function loggedin()
- {
- if(isset($_SESSION['user_session']))
- {
- return true;
- }
- }
- }
- $clas = new userclass();
- ?>
- <?php
- include_once("baseController.php");
- include 'database.php';
- $file = basename($_SERVER["PHP_SELF"],".php");
- $className = $file."Controller";
- $controller = "controller/".$file."Controller.php";
- if(file_exists($controller))
- {
- include($controller);
- $obj = new $className();
- }
- ?>
- <?php
- session_start();
- class indexController extends baseController{
- function __construct() {
- parent::__construct();
- $this->title="Home";
- if(isset($_POST["login"])){
- $this->login();
- }
- }
- public function login()
- {
- extract($_POST);
- if($this->$clas->login('users','user_name','password',$usname,$uspswd))
- {
- $this->$clas->redirect("BASE_PATH/../pages/home");
- }
- else
- {
- $this->errormsg = "Username or Password Incorrect";
- $error=false;
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement