Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once('dbconfig.php');
- class USER
- {
- private $conn;
- public function __construct()
- {
- $database = new Database();
- $db = $database->dbConnection();
- $this->conn = $db;
- }
- public function runQuery($sql)
- {
- $stmt = $this->conn->prepare($sql);
- return $stmt;
- }
- public function register($uname,$umail,$upass)
- {
- try
- {
- $new_password = password_hash($upass, PASSWORD_DEFAULT);
- $stmt = $this->conn->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 doLogin($uname,$umail,$upass)
- {
- try
- {
- $stmt = $this->conn->prepare("SELECT user_id, user_name, user_email,
- user_pass FROM users WHERE user_name=:uname OR user_email=:umail ");
- $stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
- $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
- if($stmt->rowCount() == 1)
- {
- 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 doLogout()
- {
- session_destroy();
- unset($_SESSION['user_session']);
- return true;
- }
- }
- ?>
- <?php
- require_once("session.php");
- require_once("class.user.php");
- $auth_user = new USER();
- $user_id = $_SESSION['user_session'];
- $stmt = $auth_user->runQuery("SELECT * FROM users WHERE user_id=:user_id");
- $stmt->execute(array(":user_id"=>$user_id));
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>welcome - <?php print($userRow['user_email']); ?></title>
- </head>
- <body>
- <label class="h5">welcome : <?php print($userRow['user_name']); ?></label>
- <h1>Memberlist</h1>
- <table border='1'>
- <tr>
- <th>Date</th>
- <th>Name</th>
- <th>Amount</th>
- </tr>
- <?php foreach($rows as $row): ?>
- <tr>
- <td><?php echo htmlentities($Row['date'], ENT_QUOTES, 'UTF-8'); ?></td>
- <td><?php echo htmlentities($row['name'], ENT_QUOTES, 'UTF-8'); ?></td>
- <td><?php echo htmlentities($row['amount'], ENT_QUOTES, 'UTF-8'); ?></td>
- </tr>
- <?php endforeach; ?>
- </table><br />
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement