PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/register.php

https://bitbucket.org/mhell/mhmcr
PHP | 71 lines | 57 code | 11 blank | 3 comment | 15 complexity | 5f051a808da3d4c574f70bdf42c9ad25 MD5 | raw file
  1. <?php
  2. header('Content-Type: text/html;charset=UTF-8');
  3. require_once('system.php');
  4. if (!$_POST) {
  5. //Page generation
  6. $static = array();
  7. $ql = mysql_query("SELECT `name`,`url` FROM ".$db['tables']['static']." ORDER BY `id` DESC;");
  8. while ($entry = mysql_fetch_assoc($ql))
  9. {
  10. if ($entry['url']!='main')
  11. $static[] = $entry;
  12. }
  13. $opts = array();
  14. $ql = mysql_query("SELECT * FROM ".$db['tables']['data'].";");
  15. while ($entry = mysql_fetch_assoc($ql))
  16. {
  17. $opts[$entry['property']] = $entry['value'];
  18. }
  19. include_once $config['style_dir'].'register.html';
  20. } else {
  21. //Checking input
  22. $email = $_POST['email'];
  23. $pass = $_POST['pass'];
  24. $pass2 = $_POST['pass2'];
  25. $login = $_POST['login'];
  26. $flags = array('pass'=>false,'email'=>false,'login'=>false,'captcha'=>false,'hit'=>false,'canreg'=>false);
  27. if (!preg_match("/^(?=.{1,30}$)[a-zA-Z][a-zA-Z0-9]*$/",$login)) {
  28. $flags['hit'] = true;
  29. $flags['login'] = true;
  30. }
  31. if (!CanRegister()) {
  32. $flags['hit'] = true;
  33. $flags['canreg'] = true;
  34. }
  35. if (!filter_var($email,FILTER_VALIDATE_EMAIL)) {
  36. $flags['hit'] = true;
  37. $flags['email'] = true;
  38. }
  39. if (strlen($pass)<6 or $pass!=$pass2) {
  40. $flags['hit'] = true;
  41. $flags['pass'] = true;
  42. }
  43. if (empty($_SESSION['captcha']) || trim(strtolower($_POST['captcha'])) != $_SESSION['captcha']) {
  44. $flags['hit'] = true;
  45. $flags['captcha'] = true;
  46. }
  47. //Checking done
  48. if (!$flags['hit']) {
  49. include_once('inc/pass.inc.php');
  50. $hash = createPass($pass);
  51. $login = mysql_real_escape_string($login);
  52. $email = mysql_real_escape_string($email);
  53. mysql_query("INSERT INTO ".$db['tables']['users']." (".$db['users']['username'].",".$db['users']['password'].",".$db['users']['ip'].") VALUES('".$login."','".$hash."','".GetRealIp()."');");
  54. if ($ipban = mgetOpt('ip-ban') && $ipban) {
  55. mysql_query("INSERT INTO ".$db['tables']['users']." (IP,time_start,ban_until) VALUES ('".$_SERVER['REMOTE_ADDR']."',NOW(),NOW()+INTERVAL ".$ipban." HOUR);");
  56. }
  57. Header('Location: '.mgetOpt('url-base')."?reg=ok");
  58. }
  59. }
  60. ?>