Quote database webapp
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?PHP
  2. require_once('inc/database.php');
  3. require_once('inc/settings.php');
  4. require_once('inc/account.php');
  5. function oink() {
  6. if (isset($_POST['user']) && isset($_POST['pass']) && isset($_POST['pass2'])) {
  7. if ($_POST['pass2'] != $_POST['pass']) {
  8. define('MESSAGE', 'Your passwords do not match.');
  9. return;
  10. }
  11. if (strlen($_POST['pass']) < 5) {
  12. define('MESSAGE', 'Your password must be at least 5 characters.');
  13. return;
  14. }
  15. if (strlen($_POST['user']) < 3) {
  16. define('MESSAGE', 'Your username must be at least 3 characters.');
  17. return;
  18. }
  19. if (strlen($_POST['user']) > 20) {
  20. define('MESSAGE', 'Your username must be at most 20 characters.');
  21. return;
  22. }
  23. if (!preg_match('/^[a-zA-Z0-9\-]+$/', $_POST['user'])) {
  24. define('MESSAGE', 'Your username may only contain letters, numbers and hyphens.');
  25. return;
  26. }
  27. $sql = 'SELECT user_id FROM users WHERE user_name LIKE \''.m($_POST['user']).'\'';
  28. $res = mysql_query($sql);
  29. if (mysql_num_rows($res) > 0) {
  30. define('MESSAGE', 'That username is in use. Please try another.');
  31. return;
  32. }
  33. $sql = 'INSERT INTO users (user_name, user_pass) VALUES (\''.m($_POST['user']).'\', \''.m(md5($_POST['user'].$_POST['pass'])).'\')';
  34. $res = mysql_query($sql);
  35. $id = mysql_insert_id();
  36. $_SESSION['uid'] = $id;
  37. $_SESSION['uname'] = $_POST['user'];
  38. $_SESSION['standing'] = 0;
  39. if (isset($_POST['remember'])) {
  40. $row = mysql_fetch_array(mysql_query('SELECT user_hash FROM users WHERE user_id = '.$_SESSION['uid']));
  41. if (strlen($row[0]) != 32) {
  42. $row[0] = md5(uniqid($row['user_id']).time());
  43. mysql_query('UPDATE users SET user_hash = \''.$row[0].'\' WHERE user_id = '
  44. .$_SESSION['uid']);
  45. }
  46. setcookie('quotedbperm', $row[0], time()+60*24*24*365.24);
  47. }
  48. header('Location: '.BASE);
  49. exit;
  50. }
  51. }
  52. oink();
  53. define('TITLE', 'Register');
  54. require_once('inc/header.php');
  55. ?>
  56. <div class="oneThird right">
  57. <h2>Why register?</h2>
  58. <p>
  59. Because of the public nature of this quotes database (there are no
  60. moderators or admins, just users), and the way we reward good users
  61. and punish bad ones (standings), we require that you be logged in in
  62. order to rate a quote or add a new one.
  63. </p>
  64. <p>
  65. In order to log in to the site, you first need a user account. To obtain
  66. an account, simply fill out the form to the left.
  67. </p>
  68. </div>
  69. <div>
  70. <h2>Register</h2>
  71. <?PHP
  72. if (defined('MESSAGE')) { echo '<div id="message">'.MESSAGE.'</div>'; }
  73. ?>
  74. <p>
  75. If you already have an account, you should
  76. <a href="<?PHP echo BASE; ?>login">login</a> instead.
  77. </p>
  78. <form action="<?PHP echo BASE; ?>register" method="post">
  79. <table class="form">
  80. <tr>
  81. <th>Username</th>
  82. <td><input type="text" name="user"></td>
  83. </tr>
  84. <tr>
  85. <th>Password</th>
  86. <td><input type="password" name="pass"></td>
  87. </tr>
  88. <tr>
  89. <th>Confirm password</th>
  90. <td><input type="password" name="pass2"></td>
  91. </tr>
  92. <tr>
  93. <th>Remember?</th>
  94. <td><input type="checkbox" name="remember" style="width: 20px;"> (Requires cookies)</td>
  95. </tr>
  96. </table>
  97. <input type="submit" value="Login">
  98. </form>
  99. </div>
  100. <?PHP
  101. require_once('inc/footer.php');
  102. ?>