Advertisement
Guest User

Untitled

a guest
Apr 27th, 2016
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. <?php
  2. class USER
  3. {
  4. private $db;
  5.  
  6. function __construct($DB_con)
  7. {
  8. $this->db = $DB_con;
  9. }
  10.  
  11. public function register($fname,$lname,$uname,$umail,$upass)
  12. {
  13. try
  14. {
  15. $new_password = password_hash($upass, PASSWORD_DEFAULT);
  16.  
  17. $stmt = $this->db->prepare("INSERT INTO users(user_name,user_email,user_pass)
  18. VALUES(:uname, :umail, :upass)");
  19.  
  20. $stmt->bindparam(":uname", $uname);
  21. $stmt->bindparam(":umail", $umail);
  22. $stmt->bindparam(":upass", $new_password);
  23. $stmt->execute();
  24.  
  25. return $stmt;
  26. }
  27. catch(PDOException $e)
  28. {
  29. echo $e->getMessage();
  30. }
  31. }
  32.  
  33. public function login($uname,$umail,$upass)
  34. {
  35. try
  36. {
  37. $stmt = $this->db->prepare("SELECT * FROM users WHERE user_name=:uname OR user_email=:umail LIMIT 1");
  38. $stmt->execute(array(':uname'=>$uname, ':umail'=>$umail));
  39. $userRow=$stmt->fetch(PDO::FETCH_ASSOC);
  40. if($stmt->rowCount() > 0)
  41. {
  42. if(password_verify($upass, $userRow['user_pass']))
  43. {
  44. $_SESSION['user_session'] = $userRow['user_id'];
  45. return true;
  46. }
  47. else
  48. {
  49. return false;
  50. }
  51. }
  52. }
  53. catch(PDOException $e)
  54. {
  55. echo $e->getMessage();
  56. }
  57. }
  58.  
  59. public function is_loggedin()
  60. {
  61. if(isset($_SESSION['user_session']))
  62. {
  63. return true;
  64. }
  65. }
  66.  
  67. public function redirect($url)
  68. {
  69. header("Location: $url");
  70. }
  71.  
  72. public function logout()
  73. {
  74. session_destroy();
  75. unset($_SESSION['user_session']);
  76. return true;
  77. }
  78.  
  79. public function back() {
  80. $previous = $_SERVER['HTTP_REFERER'];
  81. if (isset($previous)) {
  82. echo $previous;
  83. } else {
  84. return FALSE;
  85. }
  86.  
  87.  
  88. }
  89.  
  90. }
  91. ?>
  92.  
  93. <?php
  94.  
  95. include_once 'database.php';
  96.  
  97. class FORUM {
  98.  
  99. function __construct($DB_con)
  100. {
  101. $this->db = $DB_con;
  102. }
  103.  
  104. public function getColumn() {
  105. try {
  106. $query = $this->db->prepare("DESCRIBE posts");
  107. $query->execute();
  108. //retrieve the columns inside the table posts
  109. $forumrows = $query->fetchAll(PDO::FETCH_COLUMN);
  110. //Output each column Value
  111. foreach($forumrows as $forumrow) {
  112. echo $forumrow . "</br>";
  113. }
  114. } catch(PDOException $e) {
  115. echo $e->getMessage();
  116. }
  117. }
  118.  
  119. public function getColumnUrl() {
  120.  
  121. }
  122.  
  123. } //End forum class
  124.  
  125. $forum = new FORUM($DB_con);
  126. $forum->getColumn();
  127.  
  128. ?>
  129.  
  130. <?php
  131.  
  132. session_start();
  133.  
  134. $DB_host = "localhost";
  135. $DB_user = "root";
  136. $DB_pass = "";
  137. $DB_name = "dblogin";
  138.  
  139. try
  140. {
  141. $DB_con = new PDO("mysql:host={$DB_host};dbname={$DB_name}",$DB_user,$DB_pass);
  142. $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  143. }
  144. catch(PDOException $e)
  145. {
  146. echo $e->getMessage();
  147. }
  148.  
  149.  
  150. include_once 'users.php';
  151. $user = new USER($DB_con);
  152.  
  153. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement