Guest User

Untitled

a guest
Oct 16th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.20 KB | None | 0 0
  1. <?php
  2. require_once('config.php');
  3. require_once('define.php');
  4. class Session
  5. {
  6. function isOnline()
  7. {
  8. if(isset($_SESSION['username']))
  9. {
  10. if(isset($_SESSION['token']))
  11. {
  12. $username = $this->SafeText($_SESSION['username']);
  13. $get_user = mysql_query("SELECT * FROM users WHERE name = '$_SESSION[username]'");
  14. $r = mysql_fetch_array($get_user);
  15. if($_SESSION['username'] == $r['name'] && $_SESSION['token'] == $r['session_token'])
  16. {
  17. return true;
  18. }
  19. }
  20. else
  21. {
  22. return false;
  23. }
  24. }
  25. else
  26. {
  27. return false;
  28. }
  29. }
  30. function Logout()
  31. {
  32. unset($_SESSION['username']);
  33. unset($_SESSION['token']);
  34. unset($_SESSION['id']);
  35. header("Location: index.php");
  36. }
  37. function SafeText($str) { //Used to protect queries
  38. if(get_magic_quotes_gpc()){ $str = stripslashes($str); }
  39. $str = strip_tags($str);
  40. $str = mysql_real_escape_string($str);
  41. $str = htmlspecialchars($str,ENT_COMPAT,"UTF-8");
  42. return $str;
  43. }
  44. function Login($name, $pass){
  45. $_SESSION['error'] = "1";
  46. $search = mysql_query("SELECT * FROM users WHERE name = '".$name."'");
  47. if(mysql_num_rows($search) == 1)
  48. {
  49. $_SESSION['error'] = "2";
  50. $info = mysql_fetch_array($search);
  51. if(md5($pass) == $info['password'])
  52. {
  53. $_SESSION['error'] = "3";
  54. $_SESSION['username'] = $name;
  55. $_SESSION['id'] = $info['id'];
  56. $_SESSION['token'] = $this->GenerateCode(32);
  57. mysql_query("UPDATE users SET session_token = '".$_SESSION['token']."' WHERE name = '".$name."'");
  58. header("Location: forum.php");
  59. }
  60. else
  61. {
  62. $_SESSION['error'] = "The password you typed is incorrect.";
  63. }
  64. }
  65. else
  66. {
  67. $_SESSION['error'] = "The username does not exist.";
  68. }
  69. }
  70. function bbcode($str){
  71. $str = htmlentities($str);
  72. $format_search = array(
  73. '#\[b\](.*?)\[/b\]#is',
  74. '#\[i\](.*?)\[/i\]#is',
  75. '#\[u\](.*?)\[/u\]#is',
  76. '#\[s\](.*?)\[/s\]#is',
  77. '#\[notice\](.*?)\[/notice\]#is',
  78. '#\[img\](https?://.*?\.(?:jpg|jpeg|gif|png|bmp))\[/img\]#i',
  79. '#\[left](.*?)\[/left\]#is',
  80. '#\[right](.*?)\[/right\]#is',
  81. '#\[center](.*?)\[/center\]#is',
  82. '#\[url=((?:ftp|https?)://.*?)\](.*?)\[/url\]#i',
  83. '#\[url\]((?:ftp|https?)://.*?)\[/url\]#i'
  84. );
  85. $format_replace = array(
  86. '<strong>$1</strong>',
  87. '<em>$1</em>',
  88. '<span style="text-decoration: underline;">$1</span>',
  89. '<span style="text-decoration: line-through;">$1</span>',
  90. '<table width="90%" cellspacing="1" cellpadding="20" border="0" align="center"><tr><td class="code"><b>Moderator Notice:</b><br>$1</td></tr></table>',
  91. '<img src="$1" />',
  92. '<div align="left">$1</div>',
  93. '<div align="right">$1</div>',
  94. '<div align="center">$1</div>',
  95. '<a href="$1">$2</a>',
  96. '<a href="$1">$1</a>'
  97. );
  98. $str = preg_replace($format_search, $format_replace, $str);
  99. $str = nl2br($str);
  100. $str = htmlspecialchars_decode($str);
  101. return $str;
  102. }
  103. function GetID($name){
  104. $search = mysql_query("SELECT * FROM users WHERE name = '".$name."'");
  105. if(mysql_num_rows($search) == 1)
  106. {
  107. $r = mysql_fetch_array($search);
  108. return $r['id'];
  109. }
  110. else
  111. {
  112. return false;
  113. }
  114. }
  115. function check_email_address($email) {
  116. // First, we check that there's one @ symbol,
  117. // and that the lengths are right.
  118. if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
  119. // Email invalid because wrong number of characters
  120. // in one section or wrong number of @ symbols.
  121. return false;
  122. }
  123. // Split it into sections to make life easier
  124. $email_array = explode("@", $email);
  125. $local_array = explode(".", $email_array[0]);
  126. for ($i = 0; $i < sizeof($local_array); $i++) {
  127. if
  128. (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&
  129. ↪'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
  130. $local_array[$i])) {
  131. return false;
  132. }
  133. }
  134. // Check if domain is IP. If not,
  135. // it should be valid domain name
  136. if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
  137. $domain_array = explode(".", $email_array[1]);
  138. if (sizeof($domain_array) < 2) {
  139. return false; // Not enough parts to domain
  140. }
  141. for ($i = 0; $i < sizeof($domain_array); $i++) {
  142. if
  143. (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|
  144. ↪([A-Za-z0-9]+))$",
  145. $domain_array[$i])) {
  146. return false;
  147. }
  148. }
  149. }
  150. return true;
  151. }
  152. function PostNews($title, $shortstory, $content, $author) {
  153. if($title != NULL || $shortstory != NULL || $content != NULL)
  154. {
  155. mysql_query("INSERT INTO articles (`title`, `shortstory`, `content`, `author`) VALUES ('".$title."', '".$shortstory."', '".$content."', '".$author."')");
  156. }
  157. else
  158. {
  159. $_SESSION['error'] = "Looks like you left something blank!";
  160. }
  161. }
  162. function Register($name, $pass, $pas2){
  163. $name = $this->SafeText($name);
  164. $raw = $pass;
  165. $pass = md5($pass);
  166. $pas2 = md5($pas2);
  167. $search = mysql_query("SELECT * FROM users WHERE name = '".$name."'");
  168. if(mysql_num_rows($search) >= 1)
  169. {
  170. $_SESSION['error'] = "A user with this name has already registered!";
  171. }
  172. else
  173. {
  174. if($pass != $pas2)
  175. {
  176. $_SESSION['error'] = "The two passwords do not match!";
  177. }
  178. else
  179. {
  180. if((strlen($name) > 30) || (strlen($name) < 3))
  181. {
  182. $_SESSION['error'] = "Your username must be larger than 3 characters or less than 30.";
  183. }
  184. else
  185. {
  186. mysql_query("INSERT INTO users (`name`, `rank`, `password`) VALUES ('".$name."', '1', '".$pass."')");
  187. $this->Login($name, $raw);
  188. }
  189. }
  190. }
  191. }
  192. function GenerateCode($num) {
  193. // reset code
  194. $sCode = '';
  195. $aCharSet = array(1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
  196. // loop through and generate the code letter by letter
  197. for ($i = 0; $i < $num; $i++) {
  198. if (count($aCharSet) > 0) {
  199. // select random character and add to code string
  200. $sCode .= $aCharSet[array_rand($aCharSet)];
  201. } else {
  202. // select random character and add to code string
  203. $sCode .= chr(rand(65, 90));
  204. }
  205. }
  206. return $sCode;
  207. }
  208. }
  209. ?>
Add Comment
Please, Sign In to add comment