Cześć,
Napisałem sobie drobny skrypt walidacji formularza. System oczywiście działa, wszystko ładnie, tylko mam pytanie. Robię to w ten sposób:
<?php
// Check if the passwords match
if ($_POST['password'] != $_POST['confirmpass'])
{
$reg_error = 'Your passwords do not match';
include 'templates/head.tpl';
include 'templates/top.tpl';
include 'templates/register.tpl';
include 'templates/left.tpl';
include 'templates/footer.tpl';
}
if (!check_password_and_username($password))
{
$reg_error = 'Your passwords and login could not be the same';
include 'templates/head.tpl';
include 'templates/top.tpl';
include 'templates/register.tpl';
include 'templates/left.tpl';
include 'templates/footer.tpl';
}
if (!validSecurity($security))
{
// Reshow the form with an error
$reg_error = 'You provided wrong security answer';
include 'templates/head.tpl';
include 'templates/top.tpl';
include 'templates/register.tpl';
include 'templates/left.tpl';
include 'templates/footer.tpl';
}
$username = $_POST['username'];
if (!check_username($username))
{
// Reshow the form with an error
$reg_error = 'Requested username is aldready in use';
include 'templates/head.tpl';
include 'templates/top.tpl';
include 'templates/register.tpl';
include 'templates/left.tpl';
include 'templates/footer.tpl';
}
$email = $_POST['email'];
if (!check_email($email))
{
// Reshow the form with an error
$reg_error = 'Requested e-mail address is aldready in use';
include 'templates/head.tpl';
include 'templates/top.tpl';
include 'templates/register.tpl';
include 'templates/left.tpl';
include 'templates/footer.tpl';
}
?>
To tylko fragment kodu. Teraz kolej na pytanie: Czy ten kod jest napisany poprawnie?

To znaczy, czy funkcje są stosowane tak jak manual przykazał? Nie potrzebuję żadnego gotowca, tylko paru rad jak ewentualnie poprawić, zmienić. Formularz ma 11 pół, a kod walidacji zajmuje ponad 150 linijek. Dlatego własnie pytam.
Teraz pytanie poboczne. Czy muszę w każdym pliku serwisu include'ować plik init.php /łączenie z bazą/ czy tylko w tych, które tego wymagają. Register_globals mam wyłączone. Całe logowania odbywa się na sesjach, więc na chłopski rozum biorąc, nie potrzeba, ale chciałbym poznać opinie specjalistów.
Pozdrawiam
A.
Powód edycji: dodanie tagu ~Cienki1980