Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Wskazówki do klasy
GameMaker
post
Post #1





Grupa: Zarejestrowani
Postów: 149
Pomógł: 2
Dołączył: 31.01.2010
Skąd: Konstancin-Jeziorna

Ostrzeżenie: (0%)
-----


Wczoraj przysiadłem do OOP i napisałem klasę , która sprawdza czy user jest zalogowany i nadaje mu poziomy dostępu.

Proszę o wskazówki :

  1.  
  2.  
  3.  
  4.  
  5. class User {
  6. global $db;
  7. public $logged_in = null;
  8. public $user_level = null;
  9.  
  10.  
  11. function __construct()
  12. {
  13.  
  14. $this->startSession();
  15. }
  16.  
  17.  
  18. private function loginCheck()
  19. {
  20. if (isset($_SESSION['id']) && $_SESSION['id'] > 0) {
  21.  
  22.  
  23. return true;
  24. } else {
  25. return false;
  26. }
  27. }
  28.  
  29. private function levelCheck()
  30. {
  31. $id = intval($_SESSION['id']);
  32. $q = $db->query("Select * from mpa_users where id='$id'");
  33.  
  34. if($db->num_rows($q) == 1)
  35. {
  36. $row = $db->fetch_array($q);
  37.  
  38. if($row['admin'] == 1)
  39. {
  40. return 7;
  41. }elseif($row['admin'] == 0 && $row['premium'] == 1 && $row['premium_time'] > time())
  42. {
  43.  
  44. return 2;
  45.  
  46. }elseif($row['admin'] == 0 && $row['premium'] == 1 && $row['premium_time'] < time())
  47. {
  48. $db->query("Update mpa_users set premium='0' where id='$id'");
  49.  
  50. return 1;
  51.  
  52. }elseif($row['admin'] == 0 && $row['premium'] == 0)
  53. {
  54.  
  55. return 1;
  56. }
  57.  
  58. }
  59. else
  60. {
  61.  
  62. }
  63.  
  64. }
  65.  
  66.  
  67. private function startSession()
  68. {
  69. $this->logged_in = $this->loginCheck();
  70. if($this->logged_in)
  71. {
  72. $this->user_level = $this->levelCheck();
  73. }
  74. else
  75. {
  76. $this->user_level = 0;
  77. }
  78.  
  79. }
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. }
  89.  


Ten post edytował GameMaker 9.10.2011, 07:56:42
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 2.10.2025 - 22:58