Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class USER
- {
- private $db;
- function __construct($DB_con)
- {
- $this->db = $DB_con;
- }
- public function register($fname,$lname,$uname,$umail,$upass)
- {
- try
- {
- $new_password = password_hash($upass, PASSWORD_DEFAULT);
- $stmt = $this->db->prepare("INSERT INTO users(user_name,user_email,user_pass)
- VALUES(:uname, :umail, :upass)");
- $stmt->bindparam(":uname", $uname);
- $stmt->bindparam(":umail", $umail);
- $stmt->bindparam(":upass", $new_password);
- $stmt->execute();
- return $stmt;
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- }
- public function login($uname,$umail,$upass)
- {
- try
- {
- $stmt = $this->db->prepare("SELECT * FROM users WHERE user_name=:uname OR user_email=:umail LIMIT 1");
- $stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
- $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
- if($stmt->rowCount() > 0)
- {
- if(password_verify($upass, $userRow['user_pass']))
- {
- $_SESSION['user_session'] = $userRow['user_id'];
- return true;
- }
- else
- {
- return false;
- }
- }
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- }
- public function is_loggedin()
- {
- if(isset($_SESSION['user_session']))
- {
- return true;
- }
- }
- public function redirect($url)
- {
- header("Location: $url");
- }
- public function logout()
- {
- session_destroy();
- unset($_SESSION['user_session']);
- return true;
- }
- public function back() {
- $previous = $_SERVER['HTTP_REFERER'];
- if (isset($previous)) {
- echo $previous;
- } else {
- return FALSE;
- }
- }
- }
- ?>
- <?php
- include_once 'database.php';
- class FORUM {
- function __construct($DB_con)
- {
- $this->db = $DB_con;
- }
- public function getColumn() {
- try {
- $query = $this->db->prepare("DESCRIBE posts");
- $query->execute();
- //retrieve the columns inside the table posts
- $forumrows = $query->fetchAll(PDO::FETCH_COLUMN);
- //Output each column Value
- foreach($forumrows as $forumrow) {
- echo $forumrow . "</br>";
- }
- } catch(PDOException $e) {
- echo $e->getMessage();
- }
- }
- public function getColumnUrl() {
- }
- } //End forum class
- $forum = new FORUM($DB_con);
- $forum->getColumn();
- ?>
- <?php
- session_start();
- $DB_host = "localhost";
- $DB_user = "root";
- $DB_pass = "";
- $DB_name = "dblogin";
- try
- {
- $DB_con = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
- $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch(PDOException $e)
- {
- echo $e->getMessage();
- }
- include_once 'users.php';
- $user = new USER($DB_con);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement