Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Kohana]Fatal error: Exception thrown without a stack...
Forum PHP.pl > Forum > PHP > Frameworki
bobi194
Wykorzystałem klasę Usersession do obsługi sesji w bazie  (z podręcznika PHP5 zaawansowane programowanie)
Klasę umieściłem w kohanie 3.2 jako moduł i generalnie wszystko było ok.

Chciałem jednak użyć modułu database i podłączyć się przez pdo zamiast pg_connect ....
Generalnie wszystko (logowanie i sesje w bazie) działa ale po tej zmianie pod koniec strony mam

Fatal error: Exception thrown without a stack frame in Unknown on line 0
kod usersession.php
  1. <?php defined('SYSPATH') or die('No direct script access.');
  2. class Kohana_Usersession {
  3. private $php_session_id;
  4. public $native_session_id;
  5. private $dbhandle;
  6. private $logged_in;
  7. private $user_id;
  8. private $session_timeout = 600; # 10 minutowy maksymalny czas nieaktywno?ci sesji
  9. private $session_lifespan = 3600; # 1 godzinny maksymalny czas trwania sesji.
  10.  
  11.  
  12. public function __construct() {
  13. $this->dbhandle=Database::instance();
  14. array(&$this, '_session_open_method'),
  15. array(&$this, '_session_close_method'),
  16. array(&$this, '_session_read_method'),
  17. array(&$this, '_session_write_method'),
  18. array(&$this, '_session_destroy_method'),
  19. array(&$this, '_session_gc_method')
  20. );
  21. $strUserAgent = $_SERVER["HTTP_USER_AGENT"];
  22. $IP = $_SERVER['REMOTE_ADDR'];
  23. if (isset($_COOKIE['PHPSESSID'])) {
  24. $this->php_session_id = $_COOKIE["PHPSESSID"];
  25. $stmt = "SELECT id FROM sesja_uzytkownika WHERE identyfikator_sesji_ascii = '" . $this->php_session_id . "' AND ((now() - utworzono) < ' " . $this->session_lifespan . " seconds') AND ip='".$IP."' AND user_agent='" . $strUserAgent . "' AND ((now() - ostatnia_reakcja) <= '".$this->session_timeout." seconds' OR ostatnia_reakcja IS NULL)";
  26. $result=$this->dbhandle->query(Database::SELECT,$stmt,false)->as_array();
  27. if (count($result)==0) {
  28. $failed = 1;
  29. $result=$this->dbhandle->query(Database::UPDATE,"UPDATE sesja_uzytkownika SET zalogowany=false WHERE (now() - utworzono) > ' " . $this->session_lifespan . " seconds'",false);
  30. $result=$this->dbhandle->query(Database::DELETE,"DELETE FROM \"zmienna_sesji\" WHERE identyfikator_sesji NOT IN (SELECT id FROM \"sesja_uzytkownika\")",false);
  31. unset($_COOKIE['PHPSESSID']);
  32. };
  33. };
  34. session_set_cookie_params($this->session_lifespan);
  35. }
  36.  
  37. public function Impress() {
  38. if ($this->native_session_id) {
  39. $result=$this->dbhandle->query(Database::UPDATE,"UPDATE \"sesja_uzytkownika\" SET ostatnia_reakcja = now() WHERE id = " . $this->native_session_id,false);
  40. };
  41. }
  42.  
  43. public function IsLoggedIn() {
  44. return($this->logged_in);
  45. }
  46.  
  47. public function Get_native_id(){
  48. return($this->native_session_id);
  49. }
  50.  
  51. public function GetUserID() {
  52. if ($this->logged_in) {
  53. return($this->user_id);
  54. } else {
  55. return(false);
  56. };
  57. }
  58.  
  59. public function GetUserObject() {
  60. if ($this->logged_in) {
  61. if (class_exists("user")) {
  62. $objUser = new User($this->user_id);
  63. return($objUser);
  64. } else {
  65. return(false);
  66. };
  67. };
  68. }
  69.  
  70. public function GetSessionIdentifier() {
  71. return($this->php_session_id);
  72. }
  73.  
  74. public function Login($strUsername, $strPlainPassword) {
  75. // $strMD5Password = md5($strPlainPassword);
  76. $strMD5Password = $strPlainPassword;
  77. $strUsername = trim($strUsername);
  78. $strUsername = strip_tags($strUsername);
  79. $strUsername = str_replace('DELETE','j',$strUsername);
  80. $strUsername = str_replace('UPDATE','j',$strUsername);
  81. $strUsername = str_replace('INSERT','j',$strUsername);
  82. $strUsername = str_replace('SELECT','j',$strUsername);
  83. $strUsername = str_replace('delete','j',$strUsername);
  84. $strUsername = str_replace('update','j',$strUsername);
  85. $strUsername = str_replace('insert','j',$strUsername);
  86. $strUsername = str_replace('select','j',$strUsername);
  87.  
  88. $strPlainPassword = trim($strPlainPassword);
  89. $strPlainPassword = strip_tags($strPlainPassword);
  90. $strPlainPassword = str_replace('DELETE','j',$strPlainPassword);
  91. $strPlainPassword = str_replace('UPDATE','j',$strPlainPassword);
  92. $strPlainPassword = str_replace('INSERT','j',$strPlainPassword);
  93. $strPlainPassword = str_replace('SELECT','j',$strPlainPassword);
  94. $strPlainPassword = str_replace('delete','j',$strPlainPassword);
  95. $strPlainPassword = str_replace('update','j',$strPlainPassword);
  96. $strPlainPassword = str_replace('insert','j',$strPlainPassword);
  97. $strPlainPassword = str_replace('select','j',$strPlainPassword);
  98.  
  99.  
  100. $stmt = "SELECT id FROM \"uzytkownik\" WHERE nazwa_uzytkownika = '$strUsername' AND md5_haslo = '$strMD5Password'";
  101. $result=$this->dbhandle->query(Database::SELECT,$stmt,false)->as_array();
  102. if (count($result)>0) {
  103. foreach($result as $row){
  104. $this->user_id = $row["id"];
  105. $this->logged_in = true;
  106. $result=$this->dbhandle->query(Database::UPDATE,"UPDATE \"sesja_uzytkownika\" SET zalogowany = true, identyfikator_uzytkownika = " . $this->user_id . " WHERE id = " . $this->native_session_id,false);
  107. }
  108. return(true);
  109. } else {
  110. return(false);
  111. };
  112. }
  113.  
  114. public function LogOut() {
  115. if ($this->logged_in == true) {
  116. $result=$this->dbhandle->query(Database::UPDATE,"UPDATE \"sesja_uzytkownika\" SET zalogowany = false WHERE id = " . $this->native_session_id,false);
  117. $this->logged_in = false;
  118. $this->user_id = 0;
  119. return(true);
  120. } else {
  121. return(false);
  122. };
  123. }
  124.  
  125. public function _unset($zmienna){
  126. $result=$this->dbhandle->query(Database::DELETE,"DELETE FROM zmienna_sesji WHERE nazwa_zmiennej = '".$zmienna."' AND identyfikator_sesji=".$this->native_session_id,false);
  127. return($result);
  128. }
  129.  
  130. public function __get($nm) {
  131. $result=$this->dbhandle->query(Database::SELECT,"SELECT wartosc_zmiennej FROM zmienna_sesji WHERE identyfikator_sesji = " . $this->native_session_id . " AND nazwa_zmiennej = '" . $nm . "'",false)->as_array();
  132. if (count($result)>0) {
  133. foreach($result as $row){
  134. return(unserialize($row["wartosc_zmiennej"]));
  135. }
  136. } else {
  137. return(false);
  138. };
  139. }
  140.  
  141.  
  142. public function __set($nm, $val) {
  143. $strSer = serialize($val);
  144. $stmt = "INSERT INTO zmienna_sesji(identyfikator_sesji, nazwa_zmiennej, wartosc_zmiennej) VALUES(" . $this->native_session_id . ", '$nm', '$strSer')";
  145. $result=$this->dbhandle->query(Database::INSERT,$stmt,false);
  146. }
  147.  
  148.  
  149. private function _session_open_method($save_path, $session_name) {
  150. # Do nothing
  151. return(true);
  152. }
  153.  
  154. private function _session_close_method() {
  155. pg_close($this->dbhandle);
  156. return(true);
  157. }
  158.  
  159. private function _session_read_method($id) {
  160. $strUserAgent = $_SERVER["HTTP_USER_AGENT"];
  161. $IP = $_SERVER['REMOTE_ADDR'];
  162. $this->php_session_id = $id;
  163. $failed = 1;
  164. $result=$this->dbhandle->query(Database::SELECT,"SELECT id, zalogowany, identyfikator_uzytkownika FROM \"sesja_uzytkownika\" WHERE identyfikator_sesji_ascii = '$id'",false)->as_array();
  165. if (count($result)>0) {
  166. foreach($result as $row){
  167. $this->native_session_id = $row["id"];
  168. if ($row["zalogowany"]=="t") {
  169. $this->logged_in = true;
  170. $this->user_id = $row["identyfikator_uzytkownika"];
  171. } else {
  172. $this->logged_in = false;
  173. };
  174. }
  175. } else {
  176. $this->logged_in = false;
  177. $result=$this->dbhandle->query(Database::INSERT,"INSERT INTO sesja_uzytkownika(identyfikator_sesji_ascii, zalogowany, identyfikator_uzytkownika, utworzono, user_agent, ip) VALUES ('$id','f',0,now(),'$strUserAgent','$IP')",false);
  178. $result=$this->dbhandle->query(Database::SELECT,"SELECT id from \"sesja_uzytkownika\" WHERE identyfikator_sesji_ascii = '$id'",false)->as_array();
  179. foreach($result as $row){
  180. $this->native_session_id = $row["id"];
  181. }
  182. };
  183. return("");
  184. }
  185.  
  186. private function _session_write_method($id, $sess_data) {
  187. return(true);
  188. }
  189.  
  190. private function _session_destroy_method($id) {
  191. $result=$this->dbhandle->query(Database::DELETE,"DELETE FROM \"sesja_uzytkownika\" WHERE identyfikator_sesji_ascii = '.$id.'",false);
  192. return($result);
  193. }
  194.  
  195.  
  196. private function _session_gc_method($maxlifetime) {
  197. return(true);
  198. }
  199.  
  200. public function __destruct(){
  201. }
  202.  
  203.  
  204. }

Jak to zdiagnozować
pedro84
Popraw BBCode i wrzuć cały kod.

Kohana przecież umożliwia przechowywanie sesji w bazie.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.