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.

139 lines
3.4 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. $result = @mysql_fetch_array(DataBase::sql_query($sql,'GENERAL','Could not add new session.',true));
  54. return $result;
  55. }
  56. }
  57. function SessDeleteOld()
  58. {
  59. $time = time();
  60. $sql = "DELETE FROM ".SESSIONS_TABLE." WHERE time+129600<$time;";
  61. DataBase::sql_query($sql, 'GENERAL','Could not delete session',true);
  62. }
  63. function SessDelInvalid()
  64. {
  65. if ($_SESSION['uid']>0)
  66. {
  67. $sql = "SELECT `session_id`, `u_id` FROM ".SESSIONS_TABLE." WHERE `u_id`='".$_SESSION['uid']."'";
  68. $query = DataBase::sql_query($sql,'GENERAL','Could not obtain session information',true);
  69. $result = mysql_fetch_array($query);
  70. $result = $result['session_id'];
  71. if ($_COOKIE[SESS_NAME]!=$result)
  72. {
  73. $_SESSION['sessionid'] = '0';
  74. $_SESSION['uid'] = '0';
  75. }
  76. }
  77. }
  78. function SessDelete($uid)
  79. {
  80. $time = time();
  81. $sql = "DELETE FROM ".SESSIONS_TABLE." WHERE u_id='$uid'";
  82. $result = @mysql_fetch_array(DataBase::sql_query($sql, 'GENERAL','Could not delete session',true));
  83. $_SESSION['sessionid']='0';
  84. return $result['count'];
  85. }
  86. function SessView()
  87. {
  88. global $lng;
  89. global $user;
  90. global $forum_config;
  91. $name = '';
  92. $time = time();
  93. $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;";
  94. $query = DataBase::sql_query($sql, 'GENERAL','Could not obtain sessions information.');
  95. if (@mysql_num_rows($query)>0)
  96. {
  97. while($result = @mysql_fetch_array($query))
  98. {
  99. $uid = $result['u_id'];
  100. switch($result['rank'])
  101. {
  102. case '0':
  103. {
  104. $user_color_name = $result['nick'];
  105. break;
  106. }
  107. case '1':
  108. {
  109. $user_color_name = '<font color="'.$forum_config['color_mod'].'"><b>'.$result['nick'].'</b></font>';
  110. break;
  111. }
  112. case '2':
  113. {
  114. $user_color_name = '<font color="'.$forum_config['color_admin'].'"><b>'.$result['nick'].'</b></font>';
  115. break;
  116. }
  117. }
  118. $name .= '<a href="user.php?id='.$uid.'" class="fstandard">'.$user_color_name.'</a>, ';
  119. }
  120. }
  121. else
  122. {
  123. $name = '<span class="userlink">'.$lng['empty'].'</span>';
  124. }
  125. return array($name, @mysql_num_rows($query));
  126. }
  127. ?>