A lightweight forum engine written in PHP. Repository is now obsolete and read-only. http://www.pioder.pl/uforum.html
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
3.5 KiB

  1. <?php
  2. /**
  3. * @package uForum
  4. * @file includes/sessions.php
  5. * @version $Id$
  6. * @copyright 2009(c) PioDer <pioder@wp.pl>
  7. * @link http://pioder.gim2przemysl.int.pl/
  8. * @license GNU GPL v3
  9. **/
  10. if ( !defined('IN_uF') )
  11. {
  12. die('Hacking attempt');
  13. }
  14. //set global sessions options
  15. ini_set('session.cookie_lifetime',SESSION_LIFETIME);
  16. ini_set('session.name',SESS_NAME); //1,5 day
  17. if ((isset($_COOKIE[SESS_NAME])) && (empty($_SESSION['uid'])))
  18. {
  19. session_id($_COOKIE[SESS_NAME]);
  20. }
  21. session_start(); //starting session
  22. //check, for empty session values and set
  23. if (empty($_SESSION['uid']))
  24. {
  25. $_SESSION['uid']='0';
  26. }
  27. if (empty($_SESSION['login_on']))
  28. {
  29. $_SESSION['login_on']='0';
  30. }
  31. if (empty($_SESSION['sessionid']))
  32. {
  33. $_SESSION['sessionid']='0';
  34. }
  35. if (empty($_COOKIE['queries']))
  36. {
  37. $_COOKIE['queries']=0;
  38. setcookie('queries','0',time()+31104000);
  39. }
  40. if($_COOKIE['queries']>0)
  41. {
  42. setcookie('queries','0',time()+31104000);
  43. $_COOKIE['uid']='0';
  44. }
  45. function SessRegister()
  46. {
  47. $uid = $_SESSION['uid'];
  48. if ($uid>0)
  49. {
  50. SessDelete($uid);
  51. $time = time();
  52. $sql = "INSERT INTO ".SESSIONS_TABLE." VALUES ('', '".$_COOKIE[SESS_NAME]."','$uid','$time')";
  53. $query = DataBase::sql_query($sql,GENERAL,'Could not add new session.',true);
  54. if (DataBase::num_rows($query)>0)
  55. {
  56. $result = DataBase::fetch();
  57. return $result;
  58. }
  59. else
  60. {
  61. return false;
  62. }
  63. }
  64. }
  65. function SessDeleteOld()
  66. {
  67. $time = time();
  68. $sql = "DELETE FROM ".SESSIONS_TABLE." WHERE time+129600<$time;";
  69. DataBase::sql_query($sql, GENERAL,'Could not delete session',true);
  70. }
  71. function SessDelInvalid()
  72. {
  73. if ($_SESSION['uid']>0)
  74. {
  75. $sql = "SELECT `session_id`, `u_id` FROM ".SESSIONS_TABLE." WHERE `u_id`='".$_SESSION['uid']."'";
  76. $query = DataBase::sql_query($sql,GENERAL,'Could not obtain session information',true);
  77. $result = DataBase::fetch($query);
  78. $result = $result['session_id'];
  79. if ($_COOKIE[SESS_NAME]!=$result)
  80. {
  81. $_SESSION['sessionid'] = '0';
  82. $_SESSION['uid'] = '0';
  83. }
  84. }
  85. }
  86. function SessDelete($uid)
  87. {
  88. $time = time();
  89. $sql = "DELETE FROM ".SESSIONS_TABLE." WHERE u_id='$uid'";
  90. $query = DataBase::sql_query($sql, GENERAL,'Could not delete session',true);
  91. if (DataBase::num_rows($query)>0)
  92. {
  93. $result = DataBase::fetch($query);
  94. $_SESSION['sessionid']='0';
  95. return $result['count'];
  96. }
  97. }
  98. function SessView()
  99. {
  100. global $lng;
  101. global $user;
  102. global $forum_config;
  103. $name = '';
  104. $time = time();
  105. $sql = "SELECT ".SESSIONS_TABLE.".*, ".USERS_TABLE.".*, ".SESSIONS_TABLE.".u_id AS u_id FROM ".SESSIONS_TABLE." LEFT JOIN ".USERS_TABLE." ON ".SESSIONS_TABLE.".u_id = ".USERS_TABLE.".u_id WHERE time+1250>$time;";
  106. $query = DataBase::sql_query($sql, GENERAL,'Could not obtain sessions information.');
  107. if (DataBase::num_rows($query)>0)
  108. {
  109. while($result = DataBase::fetch($query))
  110. {
  111. $uid = $result['u_id'];
  112. switch($result['rank'])
  113. {
  114. case '0':
  115. {
  116. $user_color_name = $result['nick'];
  117. break;
  118. }
  119. case '1':
  120. {
  121. $user_color_name = '<font color="'.$forum_config['color_mod'].'"><b>'.$result['nick'].'</b></font>';
  122. break;
  123. }
  124. case '2':
  125. {
  126. $user_color_name = '<font color="'.$forum_config['color_admin'].'"><b>'.$result['nick'].'</b></font>';
  127. break;
  128. }
  129. }
  130. $name .= '<a href="user.php?id='.$uid.'" class="fstandard">'.$user_color_name.'</a>, ';
  131. }
  132. }
  133. else
  134. {
  135. $name = '<span class="userlink">'.$lng['empty'].'</span>';
  136. }
  137. return array($name, DataBase::num_rows($query));
  138. }
  139. ?>