Mam pewien problem z sesjami w logowaniu.

W pliku logowanie.php jest caly mechanizm odpowiedzialny za logowanie snitch.gif

I wszystko niby dziala jednak do tabeli w mysql o strukturze

  1. CREATE TABLE `download_admin_sesje` (
  2. `SessionID` varchar(32) collate utf8_polish_ci NOT NULL DEFAULT '',
  3. `SessionData` blob NOT NULL,
  4. `LastUsed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  5. PRIMARY KEY (`SessionID`)
  6. );



Dodaje:
SessionID SessionData LastUsed
ses4693913f6068f [BLOB - 63 B] 2007-07-10 16:01:35

Zamiast wlasnie SessionData dodaje [BLOB - 63 B] lub czasami w SessionID jest pusto

Czy w ponizszym kodzie jest blad jakis ktory to powoduje?

logowanie.php
  1. <?php
  2. function login()
  3. {
  4. $login = $_POST['login'];
  5. $password = $_POST['password'];
  6.  
  7. if (isset($login) && isset($password))
  8. {
  9.  
  10. $sql = "SELECT * FROM download_admin_users WHERE (login = '$login' AND password = '$password')";
  11. $wynik = mysql_query($sql);
  12. $rowki = mysql_num_rows($wynik);
  13.  
  14. if ($rowki == 1)
  15. {
  16. $user_id = $row[0];
  17. return (true);
  18. }
  19. }
  20.  
  21. ?>
  22. <center>
  23. <form method="post" action="<?php echo("$PHP_SELF"); ?>">
  24. <table width="200" border="0" cellspacing="1" cellpadding="1">
  25. <tr>
  26. <td width="100" valign="middle">Login:</td>
  27. <td width="100" valign="middle"><input type="text" name="login" size="20"></td>
  28. </tr>
  29. <tr>
  30. <td width="100" valign="middle">Password:</td>
  31. <td width="100" valign="middle"><input type="password" name="password" size="20"></td>
  32. </tr>
  33. </table>
  34. <input type="submit" value="Zaloguj">&nbsp;&nbsp;<input type="reset" value="Reset" size="20">
  35. </form>
  36. </center>
  37. <?
  38. return (false);
  39. }
  40.  
  41. function start()
  42. {
  43. global $SessionID, $Session, $Session_onStart;
  44. register_shutdown_function("koniec");
  45.  
  46. if(isset($SessionID) && !empty($SessionID))
  47. {
  48. $sql = "SELECT SessionData FROM download_admin_sesje WHERE SessionID='$SessionID'" .
  49. " AND UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(LastUsed) < 3600";
  50. $result = mysql_query($sql) or mysql_die();
  51.  
  52. if($row = mysql_fetch_array($result))
  53. {
  54. $Session = unserialize(stripslashes($row[0]));
  55. return;
  56. }
  57. }
  58.  
  59. if (login())
  60. {
  61. $SessionID = uniqid("ses");
  62. $Session = array();
  63. $Session["login"] = $GLOBALS["login"];
  64. $Session["password"] = $GLOBALS["password"];
  65. if(isset($GLOBALS["user_id"]))
  66. $Session["user_id"] = $GLOBALS["user_id"];
  67. $url = parse_url($GLOBALS["prefix"]);
  68. SetCookie("SessionID", $GLOBALS["SessionID"], 0, $url["path"]);
  69. }
  70. else
  71. }
  72.  
  73. function koniec()
  74. {
  75. global $SessionID, $Session;
  76.  
  77. if(isset($SessionID)) {
  78. $sql = "REPLACE INTO download_admin_sesje VALUES ('$SessionID', '" .
  79. AddSlashes(serialize($Session)) . "', null )";
  80. $foo = mysql_query($sql) or mysql_die();
  81. }
  82.  
  83. srand((double)microtime()*1000000);
  84. if(rand(1, 100) == 42)
  85. {
  86. $sql = "DELETE FROM download_admin_sesje WHERE UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(LastUsed) > 43200";
  87. $foo = mysql_query($sql) or mysql_die();
  88. }
  89. }
  90.  
  91.  
  92. function wyloguj()
  93. {
  94. global $SessionID, $Session;
  95.  
  96. $sql = "DELETE FROM download_admin_sesje WHERE SessionID='$SessionID'";
  97. $foo = mysql_query($sql) or mysql_die();
  98.  
  99. $url = parse_url($GLOBALS["prefix"]);
  100. SetCookie("SessionID", "", 0, $url["path"]);
  101.  
  102. $Session = "";
  103. $SessionID = "";
  104. unset($SessionID);
  105. unset($Session);
  106. }
  107.  
  108.  
  109. start();
  110. ?>