Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Skrypt i formularz rejestracji
- * @author Sobak
- * @package User System
- */
- require 'header.php'; // Dolacz poczatkowy kod HTML
- require 'config.php'; // Dolacz plik konfiguracyjny i polaczenie z baza
- require_once 'user.class.php';
- /**
- * Sprawdz czy formularz zostal wyslany
- */
- if ($_POST['send'] == 1) {
- // Zabezpiecz dane z formularza przed kodem HTML i ewentualnymi atakami SQL Injection
- $login = mysql_real_escape_string(htmlspecialchars($_POST['login']));
- $pass = mysql_real_escape_string(htmlspecialchars($_POST['pass']));
- $pass_v = mysql_real_escape_string(htmlspecialchars($_POST['pass_v']));
- $email = mysql_real_escape_string(htmlspecialchars($_POST['email']));
- $email_v = mysql_real_escape_string(htmlspecialchars($_POST['email_v']));
- /**
- * Sprawdz czy podany przez uzytkownika email lub login juz istnieje
- */
- $existsLogin = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM users WHERE login='$login' LIMIT 1"));
- $existsEmail = mysql_fetch_array(mysql_query("SELECT COUNT(*) FROM users WHERE email='$email' LIMIT 1"));
- $errors = ''; // Zmienna przechowujaca liste bledów które wystapily
- // Sprawdz, czy nie wystapily bledy
- if (!$login || !$email || !$pass || !$pass_v || !$email_v ) $errors .= '- Musisz wypelnic wszystkie pola<br />';
- if ($existsLogin[0] >= 1) $errors .= '- Ten login jest zajety<br />';
- if ($existsEmail[0] >= 1) $errors .= '- Ten e-mail jest juz uzywany<br />';
- if ($email != $email_v) $errors .= '- E-maile sie nie zgadzaja<br />';
- if ($pass != $pass_v) $errors .= '- Hasla sie nie zgadzaja<br />';
- /**
- * Jesli wystapily jakies bledy, to je pokaz
- */
- if ($errors != '') {
- echo '<p class="error">Rejestracja nie powiodla sie, popraw nastepujace bledy:<br />'.$errors.'</p>';
- }
- /**
- * Jesli nie ma zadnych bledów - kontynuuj rejestracje
- */
- else {
- // Posól i zasahuj haslo
- $pass = user::passSalter($pass);
- // Zapisz dane do bazy
- mysql_query("INSERT INTO users (login, email, pass) VALUES('$login','$email','$pass');") or die ('<p class="error">Wystapil blad w zapytaniu i nie udalo sie zarejestrowac uzytkownika.</p>');
- echo '<p class="success">'.$login.', zostales zarejestrowany.
- <br /><a href="index2.php?jezyk=$jezyk&strona=logowanie">Logowanie</a></p>';
- }
- }
- ?>
- <form method="post" action="">
- <label for="login">Login:</label>
- <input maxlength="32" type="text" name="login" id="login" />
- <label for="pass">Haslo:</label>
- <input maxlength="32" type="password" name="pass" id="pass" />
- <label for="pass_again">Haslo (ponownie):</label>
- <input maxlength="32" type="password" name="pass_v" id="pass_again" />
- <label for="email">Email:</label>
- <input type="text" name="email" maxlength="50" id="email" />
- <label for="email_again">Email (ponownie):</label>
- <input type="text" maxlength="255" name="email_v" id="email_again" /><br />
- <input type="hidden" name="send" value="1" />
- <input type="submit" value="Zarejestruj" />
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement