Salve vorrei capire perchè il mio form per la registrazione non funziona, ovvero
* i campi della email non segnalano l'errore se sono diverse
* i dati non vengono registrati sul database usersdb.php
* il form non viene reindirizzato alla pagina success
premetto che non sono un'esperto di php
Codice PHP:
<?php
if (session_id() == "")
{
session_start();
}
$database = './usersdb.php';
$success_page = './Registrazione_Completata!.php';
$error_message = "";
if (!file_exists($database))
{
die('User database not found!');
exit;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['form_name']) && $_POST['form_name'] == 'signupform')
{
$newusername = $_POST['username'];
$newemail = $_POST['email'];
$newpassword = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
$newfullname = $_POST['fullname'];
$confirmemail = $_POST['confirmemail'];
$code = 'NA';
if ($newpassword != $confirmpassword)
{
$error_message = 'Le 2 Password non coincidono';
}
else
if (!preg_match("/^[A-Za-z0-9_!@$]{1,50}$/", $newusername))
{
$error_message = 'Username non valido ';
}
else
if (!preg_match("/^[A-Za-z0-9_!@$]{1,50}$/", $newpassword))
{
$error_message = 'Password non valida';
}
else
if (!preg_match("/^[A-Za-z0-9_!@$.' &]{1,50}$/", $newfullname))
{
$error_message = 'Nome o Cognome non validi';
}
else
if ($newemail != $confirmemail)
{
$error_message = 'Email non uguali';
}
else
if (isset($_POST['captcha'],$_SESSION['random_txt']) && md5($_POST['captcha']) == $_SESSION['random_txt'])
{
unset($_POST['captcha'],$_SESSION['random_txt']);
}
else
{
$error_message = 'The entered code was wrong.';
}
$items = file($database, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
foreach($items as $line)
{
list($username, $password, $email, $fullname) = explode('|', trim($line));
if ($newusername == $username)
{
$error_message = 'Username attulamente in uso nel Sistema, prova con un altro';
break;
}
}
if (empty($error_message))
{
$file = fopen($database, 'a');
fwrite($file, $newusername);
fwrite($file, '|');
fwrite($file, md5($newpassword));
fwrite($file, '|');
fwrite($file, $newemail);
fwrite($file, '|');
fwrite($file, $newfullname);
fwrite($file, '|1|');
fwrite($file, $code);
fwrite($file, "\r\n");
fclose($file);
$subject = 'Your new account';
$message = 'Il tuo Account è stato creato. La ringraziamo per aversi registrato sul nostro sito';
$message .= "\r\nUsername: ";
$message .= $newusername;
$message .= "\r\nPassword: ";
$message .= $newpassword;
$message .= "\r\n";
$header = "From: tuttitrucchi@gmail.com"."\r\n";
$header .= "Reply-To: tuttitrucchi@gmail.com"."\r\n";
$header .= "MIME-Version: 1.0"."\r\n";
$header .= "Content-Type: text/plain; charset=utf-8"."\r\n";
$header .= "Content-Transfer-Encoding: 8bit"."\r\n";
$header .= "X-Mailer: PHP v".phpversion();
mail($newemail, $subject, $message, $header);
header('Location: '.$success_page);
exit;
}
}
?>
Codice HTML:
<html >
<head>
<meta charset="UTF-8">
<title>Registrazione</title>
<link href="new icon.png" rel="shortcut icon" type="image/x-icon">
<meta name="description" content="Pagina di Accesso Login sul sito tuttitrucchi.net">
<meta name="keywords" content="Login">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<div class="login-page">
<div class="form">
<form name="signupform" method="post" action="<?php echo basename(__FILE__); ?>" id="signupform">
<input type="hidden" name="form_name" value="signupform">
<form class="login-form">
<input class="input" name="nomecognome" type="text" id="fullname" placeholder="Nome e Cognome"/ required>
<input class="input" name="username" type="text" id="username" placeholder="username" required>
<input class="input" name="email" type="text" id="email" placeholder="Email" required>
<input class="input" name="confemail" type="email" id="confemail" placeholder="Conferma Email" required>
<input class="input" name="password" type="password" id="password" placeholder="Scegli una Password" required>
<input class="input" name="confpass" type="password" id="confirmpassword" placeholder="Conferma Password" required>
<button>Registrami</button>
<p class="message">Sei già registrato? <a href="./Login.php">Accedi</a></p>
</form>
</div>
<script src="js/index.js"></script>
</body>
</html>
grazie in anticipo