Advertisement
Guest User

Untitled

a guest
Apr 6th, 2017
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <?php
  2. require_once('dbconfig.php');
  3. class USER
  4. {
  5. private $conn;
  6.  
  7. public function __construct()
  8. {
  9. $database = new Database();
  10. $db = $database->dbConnection();
  11. $this->conn = $db;
  12. }
  13.  
  14. public function runQuery($sql)
  15. {
  16. $stmt = $this->conn->prepare($sql);
  17. return $stmt;
  18. }
  19.  
  20. public function register($uname,$umail,$upass)
  21. {
  22. try
  23. {
  24. $new_password = password_hash($upass, PASSWORD_DEFAULT);
  25. $stmt = $this->conn->prepare("INSERT INTO
  26. users(user_name,user_email,user_pass) VALUES(:uname, :umail, :upass)");
  27.  
  28. $stmt->bindparam(":uname", $uname);
  29. $stmt->bindparam(":umail", $umail);
  30. $stmt->bindparam(":upass", $new_password);
  31.  
  32. $stmt->execute();
  33.  
  34. return $stmt;
  35. }
  36. catch(PDOException $e)
  37. {
  38. echo $e->getMessage();
  39. }
  40. }
  41.  
  42. public function doLogin($uname,$umail,$upass)
  43. {
  44. try
  45. {
  46. $stmt = $this->conn->prepare("SELECT user_id, user_name, user_email,
  47. user_pass FROM users WHERE user_name=:uname OR user_email=:umail ");
  48. $stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
  49. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  50. if($stmt->rowCount() == 1)
  51. {
  52. if(password_verify($upass, $userRow['user_pass']))
  53. {
  54. $_SESSION['user_session'] = $userRow['user_id'];
  55. return true;
  56. }
  57. else
  58. {
  59. return false;
  60. }
  61. }
  62. }
  63. catch(PDOException $e)
  64. {
  65. echo $e->getMessage();
  66. }
  67. }
  68.  
  69. public function is_loggedin()
  70. {
  71. if(isset($_SESSION['user_session']))
  72. {
  73. return true;
  74. }
  75. }
  76.  
  77. public function redirect($url)
  78. {
  79. header("Location: $url");
  80. }
  81.  
  82. public function doLogout()
  83. {
  84. session_destroy();
  85. unset($_SESSION['user_session']);
  86. return true;
  87. }
  88. }
  89. ?>
  90.  
  91. <?php
  92.  
  93. require_once("session.php");
  94. require_once("class.user.php");
  95.  
  96. $auth_user = new USER();
  97.  
  98. $user_id = $_SESSION['user_session'];
  99.  
  100. $stmt = $auth_user->runQuery("SELECT * FROM users WHERE user_id=:user_id");
  101. $stmt->execute(array(":user_id"=>$user_id));
  102. ?>
  103.  
  104. <!DOCTYPE html>
  105. <html>
  106. <head>
  107. <title>welcome - <?php print($userRow['user_email']); ?></title>
  108. </head>
  109.  
  110. <body>
  111.  
  112. <label class="h5">welcome : <?php print($userRow['user_name']); ?></label>
  113.  
  114. <h1>Memberlist</h1>
  115. <table border='1'>
  116. <tr>
  117. <th>Date</th>
  118. <th>Name</th>
  119. <th>Amount</th>
  120.  
  121. </tr>
  122. <?php foreach($rows as $row): ?>
  123. <tr>
  124. <td><?php echo htmlentities($Row['date'], ENT_QUOTES, 'UTF-8'); ?></td>
  125. <td><?php echo htmlentities($row['name'], ENT_QUOTES, 'UTF-8'); ?></td>
  126. <td><?php echo htmlentities($row['amount'], ENT_QUOTES, 'UTF-8'); ?></td>
  127.  
  128. </tr>
  129. <?php endforeach; ?>
  130. </table><br />
  131.  
  132. </div>
  133.  
  134. </body>
  135. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement