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.

128 lines
3.4 KiB

  1. <?php
  2. /**
  3. * @package Dynamic Script Forum
  4. * @file includes/sessions.php
  5. * @version 1.0.x, 30-07-2007, 11:41
  6. * @copyright 2008(c) PioDer <pioder@wp.pl>
  7. * @link http://pioder.gim2przemysl.int.pl/dsf.html
  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 sess_register($uid)
  46. {
  47. if ($uid>0)
  48. {
  49. sess_delete($uid);
  50. $time = time();
  51. $sql = "INSERT INTO ".SESSIONS_TABLE." VALUES ('', '".$_COOKIE[SESS_NAME]."','$uid','$time')";
  52. $result = @mysql_fetch_array(DataBase::sql_query($sql,'GENERAL','Could not add new session.',true));
  53. return $result;
  54. }
  55. }
  56. function sess_delete_old()
  57. {
  58. $time = time();
  59. $sql = "DELETE FROM ".SESSIONS_TABLE." WHERE time+129600<$time;";
  60. DataBase::sql_query($sql, 'GENERAL','Could not delete session',true);
  61. }
  62. function sess_del_invalid()
  63. {
  64. if ($_SESSION['uid']>0)
  65. {
  66. $sql = "SELECT `session_id`, `u_id` FROM ".SESSIONS_TABLE." WHERE `u_id`='".$_SESSION['uid']."'";
  67. $query = DataBase::sql_query($sql,'GENERAL','Could not obtain session information',true);
  68. $result = mysql_fetch_array($query);
  69. $result = $result['session_id'];
  70. if ($_COOKIE[SESS_NAME]!=$result)
  71. {
  72. $_SESSION['sessionid'] = '0';
  73. $_SESSION['uid'] = '0';
  74. }
  75. }
  76. }
  77. function sess_delete($uid)
  78. {
  79. $time = time();
  80. $sql = "DELETE FROM ".SESSIONS_TABLE." WHERE u_id='$uid'";
  81. $result = @mysql_fetch_array(DataBase::sql_query($sql, 'GENERAL','Could not delete session',true));
  82. $_SESSION['sessionid']='0';
  83. return $result['count'];
  84. }
  85. function sess_view()
  86. {
  87. global $lng;
  88. global $user;
  89. global $forum_config;
  90. $name = '';
  91. $time = time();
  92. $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;";
  93. $query = DataBase::sql_query($sql, 'GENERAL','Could not obtain sessions information.');
  94. if (@mysql_num_rows($query)>0)
  95. {
  96. while($result = @mysql_fetch_array($query))
  97. {
  98. $uid = $result['u_id'];
  99. switch($result['rank'])
  100. {
  101. case '0':
  102. {
  103. $user_color_name = $result['nick'];
  104. break;
  105. }
  106. case '1':
  107. {
  108. $user_color_name = '<font color="'.$forum_config['color_mod'].'"><b>'.$result['nick'].'</b></font>';
  109. break;
  110. }
  111. case '2':
  112. {
  113. $user_color_name = '<font color="'.$forum_config['color_admin'].'"><b>'.$result['nick'].'</b></font>';
  114. break;
  115. }
  116. }
  117. $name .= '<a href="user.php?id='.$uid.'" class="fstandard">'.$user_color_name.'</a>, ';
  118. }
  119. }
  120. else
  121. {
  122. $name = '<span class="userlink">'.$lng['empty'].'</span>';
  123. }
  124. return array($name, @mysql_num_rows($query));
  125. }
  126. ?>