Advertisement
Guest User

Untitled

a guest
Feb 5th, 2018
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. <?php
  2. define ( 'HOST', 'localhost' );
  3. define ( 'USER', 'root' );
  4. define ( 'PASS', 'isoevumed2004' );
  5. define ( 'DB', 'oopregister' );
  6.  
  7. /** @noinspection PhpUndefinedClassInspection */
  8. class DB
  9. {
  10. function __construct ()
  11. {
  12. /** @noinspection PhpParamsInspection */
  13. $con = mysqli_connect ( HOST, USER, PASS, DB ) or die( mysqli_error () );
  14. }
  15. }
  16.  
  17. class User
  18. {
  19. public function __construct ()
  20. {
  21. /** @noinspection PhpUnusedLocalVariableInspection */
  22. $db = new DB;
  23. }
  24.  
  25. public function register ($trn_date, $name, $username, $email, $pass)
  26. {
  27. $pass = md5 ( $pass );
  28. /** @noinspection PhpParamsInspection */
  29. $con = mysqli_connect ( HOST, USER, PASS, DB ) or die( mysqli_error () );
  30. $checkuser = mysqli_query ( $con, /** @lang text */
  31. "Select id from users where email='$email'" );
  32. $result = mysqli_num_rows ( $checkuser );
  33. if ( $result == 0 ) {
  34. $register = mysqli_query ( $con, /** @lang text */
  35. "Insert into users (trn_date, name, username, email, password) values ('$trn_date','$name','$username','$email','$pass')" ) or die( mysqli_error () );
  36. return $register;
  37. } else
  38. {
  39. return false;
  40. }
  41. }
  42.  
  43. public function login ($email, $pass)
  44. {
  45. $pass = md5 ( $pass );
  46. /** @noinspection PhpParamsInspection */
  47. $con = mysqli_connect ( HOST, USER, PASS, DB ) or die( mysqli_error () );
  48. $check = mysqli_query ( $con, /** @lang text */
  49. "Select * from users where email='$email' and password='$pass'" );
  50. $data = mysqli_fetch_array ( $check );
  51. $result = mysqli_num_rows ( $check );
  52. if ( $result == 1 )
  53. {
  54. $_SESSION[ 'login' ] = true;
  55. $_SESSION[ 'id' ] = $data[ 'id' ];
  56. return true;
  57. } else
  58. {
  59. return false;
  60. }
  61. }
  62.  
  63. public function fullname ($id)
  64. {
  65. /** @noinspection PhpParamsInspection */
  66. $con = mysqli_connect ( HOST, USER, PASS, DB ) or die( mysqli_error () );
  67. $result = mysqli_query ( $con, /** @lang text */
  68. "Select * from users where id='$id'" );
  69. $row = mysqli_fetch_array ( $result );
  70. echo $row[ 'name' ];
  71. }
  72.  
  73. public function session ()
  74. {
  75. if ( isset( $_SESSION[ 'login' ] ) ) {
  76. return $_SESSION[ 'login' ];
  77. }
  78. }
  79.  
  80. public function logout ()
  81. {
  82. $_SESSION[ 'login' ] = false;
  83. session_destroy ();
  84. }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement