我的javascript / php页面有问题: 当有人在我的网站上进行连接或注册时,我已经执行了java系统警报。我可以正确连接我的帐户,但是出现错误信息(我让您看到我的代码)
$(document).ready(function() {
$('#register_me').on('submit', function(e) {
e.preventDefault();
var $this = $(this);
var pseudonyme = $('#bean_name').val();
var mail = $('#bean_email').val();
var pswd = $('#bean_password').val();
var repswd = $('#bean_repassword').val();
if (pseudonyme === '' || pswd === '' || repswd === '' || mail === '') {
swal("Oops :(", "Les champs doivent être remplis.", "error");
} else {
$.ajax({
url: $this.attr('action'),
type: $this.attr('method'),
data: $this.serialize(),
success: function(html) {
if (html == "97736e1f6d89487783cb1b464745817b") {
swal({
title: "Création en cours...",
text: "Vous pouvez à présent vous connectez.",
type: "success",
timer: 800,
showConfirmButton: false
});
window.setTimeout(function() {
window.location = "/moi";
}, 1000);
} else {
swal("Oops :(", html, "error");
}
}
});
}
});
});
现在我注册PHP表格:
<form class="signup-form" id="register_me" action="<?= $site['lien']; ?>/app/actions/inscription.php" method="post" role="form" autocomplete="off">
<h3 class="Ang-message">Inscris-toi dès maintenant sur <span><?= $site['nom']; ?></span>!</h3>
<input type="text" name="bean_name" id="register__input" placeholder="Nom d'utilisateur" required>
<input type="email" name="bean_email" id="register__input" placeholder="Adresse mail" required>
<input type="password" name="bean_password" id="register__input" placeholder="Mot de passe" required>
<input type="password" name="bean_repassword" id="register__input" placeholder="Confirmer votre mot de passe" required>
<button type="submit" id="login__submit">Finaliser l'inscription</button>
<a href="index" id="btn__register">Annuler</a>
</form>
我只给您一张我注册时看到的屏幕截图
PHP脚本:
<?php
require('../../global.php');
if(isset($_SESSION['id'])) {
die('Une erreur est survenue.');
}
if(isset($_POST['bean_name'],$_POST['bean_email'],$_POST['bean_password'],$_POST['bean_repassword'])) {
if(!empty($_POST['bean_name']) AND !empty($_POST['bean_email']) AND !empty($_POST['bean_password']) AND !empty($_POST['bean_repassword'])) {
$pseudo = htmlspecialchars($_POST['bean_name']);
$email = htmlspecialchars($_POST['bean_email']);
$password = password_hash($_POST['bean_password'], PASSWORD_BCRYPT);
$pseudo_exist = $bdd->prepare('SELECT * FROM users WHERE username = :username');
$pseudo_exist->execute([
'username' => $pseudo
]);
if($pseudo_exist->rowCount() == 0) {
if(preg_match('`^([a-zA-Z0-9-=?!@:.,]{3,15})$`', $pseudo)) {
$email_exist = $bdd->prepare('SELECT * FROM users WHERE mail = :mail');
$email_exist->execute([
'mail' => $email
]);
if($email_exist->rowCount() == 0) {
if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
if($_POST['bean_password'] == $_POST['bean_repassword']) {
if(strlen($_POST['bean_password']) >= 6 AND strlen($_POST['bean_password']) >= 6) {
$insert_membre = $bdd->prepare('INSERT INTO users(username, password, mail, rank, credits, vip_points, activity_points, look, gender, motto, account_created, last_online, ip_reg) VALUES (:username, :password, :mail, :rank, :credits, :vip_points, :activity_points, :look, :gender, :motto, :account_created, :last_online, :ip_reg)');
$insert_membre->execute([
'username' => $pseudo,
'password' => $password,
'mail' => $email,
'rank' => "1",
'credits' => "1000000",
'vip_points' => "0",
'activity_points' => "1000000",
'look' => "hr-831-61.sh-290-62.ch-3208-110-92.hd-180-2.lg-275-62",
'gender' => "M",
'motto' => "Je suis nouveau !",
'account_created' => time(),
'last_online' => time(),
'ip_reg' => $_SERVER['REMOTE_ADDR']
]);
$_SESSION['id'] = $bdd->lastInsertId();
echo '97736e1f6d89487783cb1b464745817b';
} else {
echo 'Le mot de passe doit contenir plus de 6 caractères.';
}
} else {
echo 'Les mots de passe ne correspondent pas.';
}
} else {
echo 'L\'adresse e-mail n\'est pas valide.';
}
} else {
echo 'Cette adresse e-mail est déjà utilisée.';
}
} else {
echo 'Ton pseudo contient des caractères non-autorisés.';
}
} else {
echo 'Ce pseudo est déjà utilisé.';
}
} else {
echo 'Merci de remplir tous les champs.';
}
}
?>