Connexion
S'inscrire
Actualités
Quoi de neuf
Activités générales
Auteurs
Forums
Nouveaux messages
Rechercher un forum
Quoi de neuf
Nouveaux messages
Nouveaux messages de profil
Activités générales
Membres
Membres inscrits
Visiteurs actuels
Nouveaux messages de profil
Rechercher dans les messages des profils
Teams
Créé ton équipe
Quoi de neuf ?
Nouveaux messages
Rechercher un forum
Menu
Connexion
S'inscrire
Install the app
Install
Forums
Forums généraux
Informatique
Développement
#1 Créer un espace membre | Inscription
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Vous utilisez un navigateur non à jour ou ancien. Il ne peut pas afficher ce site ou d'autres sites correctement.
Vous devez le mettre à jour ou utiliser un
navigateur alternatif
.
Répondre à la discussion
Message
<blockquote data-quote="WhiiTe'" data-source="post: 5710980" data-attributes="member: 8987"><p><span style="font-size: 12px">Salut <img src="/images/smileys/smiley-rg.svg" class="smilie" loading="lazy" alt=":RG:" title="RG :RG:" data-shortname=":RG:" />,</span></p><p><span style="font-size: 12px"></span></p><p style="text-align: center"><span style="font-size: 12px">Je vais vous faire <strong><span style="color: #0059b3">une série de quatre tutoriels</span></strong> tout au long du mois, les quatre tutoriels seront sur <strong><span style="color: #0059b3">la création d'un espace membre</span></strong>, cette semaine je vais faire <strong><span style="color: #0059b3">la partie inscription</span></strong>, la seconde semaine sera sur <strong><span style="color: #0059b3">la connexion</span></strong>, la troisième sur <strong><span style="color: #0059b3">le profil</span></strong> et la dernière semaine sera basé sur <strong><span style="color: #0059b3">l'édition du profil</span></strong>.</span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p> <p style="text-align: center"><span style="font-size: 12px">Faîtes attention quand vous allez c/C <strong><span style="color: #0059b3">enlevez le BBCode qui s'est incrusté </span></strong>dans les SPOILER, RG bug et<strong><span style="color: #0059b3"> je ne peux pas les enlever</span></strong>. :@</span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p> <p style="text-align: center"><span style="font-size: 12px">J'utiliserai l'éditeur de texte <strong><span style="color: #0059b3">Sublime Text 3</span></strong>.</span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p> <p style="text-align: center"><span style="font-size: 12px"><img src="https://reality-gaming.fr/attachments/djamel4-png.61409/" alt="" class="fr-fic fr-dii fr-draggable " style="" /></span></p> <p style="text-align: center"></p> <p style="text-align: center"><span style="font-size: 12px">Donc commençons, nous allons créer <strong><span style="color: #0059b3">une nouvelle base de donnée</span></strong> que nous appellerons "<strong><span style="color: #0059b3">espace_membre</span></strong>" et dedans nous allons créer <strong><span style="color: #0059b3">la table "membres"</span></strong> avec comme paramètres<strong><span style="color: #0059b3"> un id en auto-increment et avec un index primaire, pseudo et mail en VARCHAR de 255 et motdepasse en TEXT</span></strong>, voici ce que vous devriez avoir : <strong><a href="http://prntscr.com/80ed7x" target="_blank">http://prntscr.com/80ed7x</a> </strong><img src="/images/smiley-pack/oui.gif" class="smilie" loading="lazy" alt=":oui:" title="Oui :oui:" data-shortname=":oui:" /></span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p> <p style="text-align: center"><span style="font-size: 12px"><img src="https://reality-gaming.fr/attachments/djamel4-png.61409/" alt="" class="fr-fic fr-dii fr-draggable " style="" /></span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p> <p style="text-align: center"><span style="font-size: 12px">Maintenant commençons à coder, créons un fichier "<strong><span style="color: #0059b3">inscription.php</span></strong>" et ouvrez le.</span></p> <p style="text-align: center"><span style="font-size: 12px">Nous allons commencer par faire<span style="color: #0059b3"> <strong>le formulaire d'inscription</strong></span>, je vous l'ai fais d'avance.</span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p> <p style="text-align: center"><span style="font-size: 12px">[SPOILER="Base html"][HTML]<!DOCTYPE html><html></span></p> <p style="text-align: center"><span style="font-size: 12px"> <head></span></p> <p style="text-align: center"><span style="font-size: 12px"> <meta charset="utf-8"></span></p> <p style="text-align: center"><span style="font-size: 12px"> <title>#1 TUTO PHP | WhiiTe'</title></span></p> <p style="text-align: center"><span style="font-size: 12px"> </head></span></p> <p style="text-align: center"><span style="font-size: 12px"> <body align="center"></span></p> <p style="text-align: center"><span style="font-size: 12px"> <h2>Inscription</h2></span></p> <p style="text-align: center"><span style="font-size: 12px"> <br /></span></p> <p style="text-align: center"><span style="font-size: 12px"> <form method="POST"></span></p> <p style="text-align: center"><span style="font-size: 12px"> <table align="center"></span></p> <p style="text-align: center"><span style="font-size: 12px"> <tr></span></p> <p style="text-align: center"><span style="font-size: 12px"> <td align="right"></span></p> <p style="text-align: center"><span style="font-size: 12px"> <label for="pseudo" >Pseudo :</label></span></p> <p style="text-align: center"><span style="font-size: 12px"> </td></span></p> <p style="text-align: center"><span style="font-size: 12px"> <td></span></p> <p style="text-align: center"><span style="font-size: 12px"> <input type="text" placeholder="Votre pseudo" id="pseudo" name="pseudo" value="<?php if(isset($pseudo)) { echo $pseudo; } ?>" /></span></p> <p style="text-align: center"><span style="font-size: 12px"> </td></span></p> <p style="text-align: center"><span style="font-size: 12px"> </tr></span></p> <p style="text-align: center"><span style="font-size: 12px"> <tr></span></p> <p style="text-align: center"><span style="font-size: 12px"> <td align="right"></span></p> <p style="text-align: center"><span style="font-size: 12px"> <label for="mail">Mail :</label></span></p> <p style="text-align: center"><span style="font-size: 12px"> </td></span></p> <p style="text-align: center"><span style="font-size: 12px"> <td></span></p> <p style="text-align: center"><span style="font-size: 12px"> <input type="email" placeholder="Votre mail" id="mail" name="mail" value="<?php if(isset($mail)) { echo $mail; } ?>" /></span></p> <p style="text-align: center"><span style="font-size: 12px"> </td></span></p> <p style="text-align: center"><span style="font-size: 12px"> </tr></span></p> <p style="text-align: center"><span style="font-size: 12px"> <tr></span></p> <p style="text-align: center"><span style="font-size: 12px"> <td align="right"></span></p> <p style="text-align: center"><span style="font-size: 12px"> <label for="mail2">Confirmation du mail :</label></span></p> <p style="text-align: center"><span style="font-size: 12px"> </td></span></p> <p style="text-align: center"><span style="font-size: 12px"> <td></span></p> <p style="text-align: center"><span style="font-size: 12px"> <input type="email" placeholder="Confirmez votre mail" id="mail2" name="mail2" value="<?php if(isset($mail2)) { echo $mail2; } ?>" /></span></p> <p style="text-align: center"><span style="font-size: 12px"> </td></span></p> <p style="text-align: center"><span style="font-size: 12px"> </tr></span></p> <p style="text-align: center"><span style="font-size: 12px"> <tr></span></p> <p style="text-align: center"><span style="font-size: 12px"> <td align="right"></span></p> <p style="text-align: center"><span style="font-size: 12px"> <label for="mdp">Mot de passe :</label></span></p> <p style="text-align: center"><span style="font-size: 12px"> </td></span></p> <p style="text-align: center"><span style="font-size: 12px"> <td></span></p> <p style="text-align: center"><span style="font-size: 12px"> <input type="password" placeholder="Votre mot de passe" id="mdp" name="mdp" /></span></p> <p style="text-align: center"><span style="font-size: 12px"> </td></span></p> <p style="text-align: center"><span style="font-size: 12px"> </tr></span></p> <p style="text-align: center"><span style="font-size: 12px"> <tr></span></p> <p style="text-align: center"><span style="font-size: 12px"> <td align="right"></span></p> <p style="text-align: center"><span style="font-size: 12px"> <label for="mdp2">Confirmation du mot de passe :</label></span></p> <p style="text-align: center"><span style="font-size: 12px"> </td></span></p> <p style="text-align: center"><span style="font-size: 12px"> <td></span></p> <p style="text-align: center"><span style="font-size: 12px"> <input type="password" placeholder="Confirmez votre mdp" id="mdp2" name="mdp2" /></span></p> <p style="text-align: center"><span style="font-size: 12px"> </td></span></p> <p style="text-align: center"><span style="font-size: 12px"> </tr></span></p> <p style="text-align: center"><span style="font-size: 12px"> <tr></span></p> <p style="text-align: center"><span style="font-size: 12px"> <td></td></span></p> <p style="text-align: center"><span style="font-size: 12px"> <td align="center"></span></p> <p style="text-align: center"><span style="font-size: 12px"> <br /></span></p> <p style="text-align: center"><span style="font-size: 12px"> <input type="submit" name="register" value="Je m'inscris" /></span></p> <p style="text-align: center"><span style="font-size: 12px"> </td></span></p> <p style="text-align: center"><span style="font-size: 12px"> </tr></span></p> <p style="text-align: center"><span style="font-size: 12px"> </table></span></p> <p style="text-align: center"><span style="font-size: 12px"> </form></span></p> <p style="text-align: center"><span style="font-size: 12px"> </body></span></p> <p style="text-align: center"><span style="font-size: 12px"></html></span></p> <p style="text-align: center"><span style="font-size: 12px">[/HTML][/SPOILER]</span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px">Si vous voulez changé le formulaire, <strong><span style="color: #0059b3">ne touchez pas au "name"</span></strong> car c'est ce qui nous servira <strong><span style="color: #0059b3">à lier l'input au PHP</span></strong>. <img src="/images/smiley-pack/y.gif" class="smilie" loading="lazy" alt=":ok:" title="D'accord :ok:" data-shortname=":ok:" /></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px">Maintenant place au PHP, nous allons faire <strong><span style="color: #0059b3">une vérification</span></strong>, c'est à dire que nous allons vérifier si l'utilisateur <strong><span style="color: #0059b3">à rentrer son pseudo, son email et son mot de passe</span></strong>, mais tout en <strong><span style="color: #0059b3">sécurisant</span></strong> le tout.</span></p></p> <p style="text-align: center"></span></p> <p style="text-align: center"><span style="font-size: 12px">[SPOILER="Vérification + Sécurisation"]</span></p> <p style="text-align: center"><span style="font-size: 12px">[PHP]$bdd = new PDO('mysql:host=127.0.0.1;dbname=espace_membre', 'root', '');[/SIZE][/SIZE][/CENTER][/SIZE][/SIZE]</span></p> <p style="text-align: center"><span style="font-size: 12px">if(isset($_POST['register']))</span></p> <p style="text-align: center"><span style="font-size: 12px"> {</span></p> <p style="text-align: center"><span style="font-size: 12px"> $pseudo = htmlspecialchars(trim($_POST['pseudo']));</span></p> <p style="text-align: center"><span style="font-size: 12px"> $mail = htmlspecialchars(trim($_POST['mail']));</span></p> <p style="text-align: center"><span style="font-size: 12px"> $mail2 = htmlspecialchars(trim($_POST['mail2']));</span></p> <p style="text-align: center"><span style="font-size: 12px"> $mdp = sha1($_POST['mdp']);</span></p> <p style="text-align: center"><span style="font-size: 12px"> $mdp2 = sha1($_POST['mdp2']);</span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p> <p style="text-align: center"><span style="font-size: 12px"> if(!empty($_POST['pseudo']) AND !empty($_POST['mail']) AND !empty($_POST['mail2']) AND !empty($_POST['mdp']) AND !empty($_POST['mdp2']))</span></p> <p style="text-align: center"><span style="font-size: 12px"> {[/PHP][/SPOILER]</span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p> <p style="text-align: center"><span style="font-size: 12px"></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px">Premièrement nous vérifions si l'utilisateur <strong><span style="color: #0059b3">à cliqué sur le bouton "submit"</span></strong> puis nous sécurisons grâce à un "<strong><span style="color: #0059b3">htmlspecialchars</span></strong>" qui sert à faire en sorte que si l'utilisateur est méchant et essaye de rentrer du code, <strong><span style="color: #0059b3">son code sera prit en texte plein</span></strong>, c'est utile surtout si il y a un système de profil car si un utilisateur gentil va sur son profil, <strong><span style="color: #0059b3">il aura le code écris et non exécuté, trim sert à enlever les espaces vides.</span></strong></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px">Vous allez me dire qu'il n'y a pas de "htmlspecialchars" mais "sha1" devant le mot de passe, c'est normal car nous <strong><span style="color: #0059b3">ne voulons pas voir les mots de passes de vos membres</span></strong>, nous voulons que leurs mots de passes soient sur de ne pas être volé si un hackeur accède à votre base de donnée, donc nous <strong><span style="color: #0059b3">les cryptons</span></strong> grâce à cette fonction, il existe aussi <strong><span style="color: #0059b3">la fonction "md5" mais elle est moins sur</span></strong>, la toute première ligne de ce spoiler est <strong><span style="color: #0059b3">la connexion à la base de donnée</span></strong>.</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><img src="https://reality-gaming.fr/attachments/djamel4-png.61409/" alt="" class="fr-fic fr-dii fr-draggable " style="" /></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px">Maintenant nous allons vérifier si<strong><span style="color: #0059b3"> les deux emails et les deux mots de passes que l'utilisateur a rentré sont identiques</span></strong>, et si l'adresse mail est <strong><span style="color: #0059b3">correcte</span></strong>, c'est à dire si l'adresse mail comporte bien un @ et la fin en .fr (ou .com...).</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px">[SPOILER="2ème vérification"]</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px">[PHP] $pseudolength = strlen($pseudo)if($pseudolength <= 25) {</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"> if($mail == $mail2)</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"> {</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"> if(filter_var($mail, FILTER_VALIDATE_EMAIL))</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"> {</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"> $reqmail = $bdd->prepare("SELECT * FROM membres WHERE mail = ?");</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"> $reqmail->execute(array($mail));</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"> $mailexist = $reqmail->rowCount();</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"> if($mailexist == 0)</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"> {</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"> if($mdp == $mdp2)</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"> {[/PHP][/SPOILER]</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"></span></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px">Donc la nous allons calculer la longueur du pseudo grâce à une fonction "<strong><span style="color: #0059b3">strlen</span></strong>", si le pseudo est <strong><span style="color: #0059b3">inférieur ou égale à 25 caractères</span></strong>, nous passons <strong><span style="color: #0059b3">à la deuxième vérification</span></strong> qui vérifie si les deux emails que l’utilisateur correspondent, si ils correspondent <strong><span style="color: #0059b3">nous passons à l'étape suivante</span></strong> qui vérifie si le mail est bon, <strong><span style="color: #0059b3">je vous ai expliqué plus haut</span></strong>, si le mail est bon nous vérifions si l'email n'existe pas déjà, si "<strong><span style="color: #0059b3">$mailexist</span></strong>" est égale à 0, ce qui veut dire que l'email <strong><span style="color: #0059b3">n'est pas dans la base de donnée</span></strong>, nous passons à <strong><span style="color: #0059b3">la dernière étape de vérification</span></strong>, nous vérifions si les deux mots de passe correspondent, si ils correspondent bien <strong><span style="color: #0059b3">nous insérons dans la base de donnée</span></strong>.</span></span></span></span></p></p> <p style="text-align: center"></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px">[SPOILER="L’insertion dans la base de donnée"]</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px">[PHP] $insertmbr = $bdd->prepare("INSERT INTO membres(pseudo, mail, motdepasse) VALUES(?, ?, ?)");$insertmbr->execute(array($pseudo, $mail, $mdp));}</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px">[/PHP][/SPOILER]</span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"></span></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px">Nous avons fait toutes les étapes de vérifications puis l’insertion dans la base de donnée.</span></span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px">Nous allons <strong><span style="color: #0059b3">mettre des messages d'erreurs</span></strong> si, par exemple, l’utilisateur rentre 26 caractères, alors il aura<strong><span style="color: #0059b3"> un message</span></strong> sous le formulaire qui lui dis que <strong><span style="color: #0059b3">la taille maximum est de 25 caractères</span></strong>.</span></span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"></span></span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px">Vous n'avez qu'à copier-coller en dessous de <strong><span style="color: #0059b3">la requête SQL</span></strong> ce qui se trouve dans le SPOILER <strong><span style="color: #0059b3">ci-dessous</span></strong>.</span></span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"></span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px">[SPOILER="Messages d'erreurs"]</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px">[PHP]else $erreur = "Vos mots de passes ne correspondent pas !";</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> }</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> }</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> else</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> {</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> $erreur = "Adresse mail déjà utilisée !";</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> }</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> }</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> else</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> {</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> $erreur = "Votre adresse mail n'est pas valide !";</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> }</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> }</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> else</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> {</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> $erreur = "Vos adresses mail ne correspondent pas !";</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> }</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> }</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> else</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> {</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> $erreur = "Votre pseudo ne doit pas dépasser 255 caractères !";</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> }</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> }</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> else</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> {</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> $erreur = "Tous les champs doivent être complétés !";</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> }</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"> }[/PHP][/SPOILER]</span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"></span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"></span></span></span></p></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"></span></span></span></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px">Et en dessous de la<strong><span style="color: #0059b3"> fermeture de la balise "form" </span></strong>en dessous de votre page nous <strong><span style="color: #0059b3">allons affiché l'erreur</span></strong>.</span></span></span></span></span></p></span></span></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"></span></span></span></span></span></p></span></span></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px">[SPOILER="Affichage de l'erreur"][PHP]<?php if(isset($erreur)) { echo $erreur; } ?>[/PHP][/SPOILER]</span></span></span></p></span></span></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"></span></span></span></p></span></span></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px">Et voila <img src="/images/smileys/smiley-rg.svg" class="smilie" loading="lazy" alt=":RG:" title="RG :RG:" data-shortname=":RG:" /> c'est la fin de <strong><span style="color: #0059b3">cette première partie</span></strong>, si vous avez un problème ou une question n'hésitez pas à <strong><span style="color: #0059b3">m'envoyer un message privée en expliquant votre soucis</span></strong>.</span></span></span></p></span></span></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"></span></span></span></p></span></span></span></p><p style="text-align: center"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><span style="font-size: 12px"><img src="/data/assets/smilies/tchuss.gif" class="smilie" loading="lazy" alt=":tchuss:" title="Tchuss :tchuss:" data-shortname=":tchuss:" /></span></span></span></p></p> <p style="text-align: center"></span></span></p> </p></p> <p style="text-align: center"></span></p></blockquote><p></p>
[QUOTE="WhiiTe', post: 5710980, member: 8987"] [SIZE=3]Salut :RG:, [/SIZE] [CENTER][SIZE=3]Je vais vous faire [B][COLOR=#0059b3]une série de quatre tutoriels[/COLOR][/B] tout au long du mois, les quatre tutoriels seront sur [B][COLOR=#0059b3]la création d'un espace membre[/COLOR][/B], cette semaine je vais faire [B][COLOR=#0059b3]la partie inscription[/COLOR][/B], la seconde semaine sera sur [B][COLOR=#0059b3]la connexion[/COLOR][/B], la troisième sur [B][COLOR=#0059b3]le profil[/COLOR][/B] et la dernière semaine sera basé sur [B][COLOR=#0059b3]l'édition du profil[/COLOR][/B]. Faîtes attention quand vous allez c/C [B][COLOR=#0059b3]enlevez le BBCode qui s'est incrusté [/COLOR][/B]dans les SPOILER, RG bug et[B][COLOR=#0059b3] je ne peux pas les enlever[/COLOR][/B]. :@ J'utiliserai l'éditeur de texte [B][COLOR=#0059b3]Sublime Text 3[/COLOR][/B]. [IMG]https://reality-gaming.fr/attachments/djamel4-png.61409/[/IMG][/SIZE] [SIZE=3]Donc commençons, nous allons créer [B][COLOR=#0059b3]une nouvelle base de donnée[/COLOR][/B] que nous appellerons "[B][COLOR=#0059b3]espace_membre[/COLOR][/B]" et dedans nous allons créer [B][COLOR=#0059b3]la table "membres"[/COLOR][/B] avec comme paramètres[B][COLOR=#0059b3] un id en auto-increment et avec un index primaire, pseudo et mail en VARCHAR de 255 et motdepasse en TEXT[/COLOR][/B], voici ce que vous devriez avoir : [B][URL]http://prntscr.com/80ed7x[/URL] [/B]:oui: [IMG]https://reality-gaming.fr/attachments/djamel4-png.61409/[/IMG] Maintenant commençons à coder, créons un fichier "[B][COLOR=#0059b3]inscription.php[/COLOR][/B]" et ouvrez le. Nous allons commencer par faire[COLOR=#0059b3] [B]le formulaire d'inscription[/B][/COLOR], je vous l'ai fais d'avance. [SPOILER="Base html"][HTML]<!DOCTYPE html><html> <head> <meta charset="utf-8"> <title>#1 TUTO PHP | WhiiTe'</title> </head> <body align="center"> <h2>Inscription</h2> <br /> <form method="POST"> <table align="center"> <tr> <td align="right"> <label for="pseudo" >Pseudo :</label> </td> <td> <input type="text" placeholder="Votre pseudo" id="pseudo" name="pseudo" value="<?php if(isset($pseudo)) { echo $pseudo; } ?>" /> </td> </tr> <tr> <td align="right"> <label for="mail">Mail :</label> </td> <td> <input type="email" placeholder="Votre mail" id="mail" name="mail" value="<?php if(isset($mail)) { echo $mail; } ?>" /> </td> </tr> <tr> <td align="right"> <label for="mail2">Confirmation du mail :</label> </td> <td> <input type="email" placeholder="Confirmez votre mail" id="mail2" name="mail2" value="<?php if(isset($mail2)) { echo $mail2; } ?>" /> </td> </tr> <tr> <td align="right"> <label for="mdp">Mot de passe :</label> </td> <td> <input type="password" placeholder="Votre mot de passe" id="mdp" name="mdp" /> </td> </tr> <tr> <td align="right"> <label for="mdp2">Confirmation du mot de passe :</label> </td> <td> <input type="password" placeholder="Confirmez votre mdp" id="mdp2" name="mdp2" /> </td> </tr> <tr> <td></td> <td align="center"> <br /> <input type="submit" name="register" value="Je m'inscris" /> </td> </tr> </table> </form> </body> </html> [/HTML][/SPOILER] [CENTER][SIZE=3]Si vous voulez changé le formulaire, [B][COLOR=#0059b3]ne touchez pas au "name"[/COLOR][/B] car c'est ce qui nous servira [B][COLOR=#0059b3]à lier l'input au PHP[/COLOR][/B]. :ok: Maintenant place au PHP, nous allons faire [B][COLOR=#0059b3]une vérification[/COLOR][/B], c'est à dire que nous allons vérifier si l'utilisateur [B][COLOR=#0059b3]à rentrer son pseudo, son email et son mot de passe[/COLOR][/B], mais tout en [B][COLOR=#0059b3]sécurisant[/COLOR][/B] le tout.[/SIZE][/CENTER] [SPOILER="Vérification + Sécurisation"] [PHP]$bdd = new PDO('mysql:host=127.0.0.1;dbname=espace_membre', 'root', '');[/SIZE][/SIZE][/CENTER][/SIZE][/SIZE] if(isset($_POST['register'])) { $pseudo = htmlspecialchars(trim($_POST['pseudo'])); $mail = htmlspecialchars(trim($_POST['mail'])); $mail2 = htmlspecialchars(trim($_POST['mail2'])); $mdp = sha1($_POST['mdp']); $mdp2 = sha1($_POST['mdp2']); if(!empty($_POST['pseudo']) AND !empty($_POST['mail']) AND !empty($_POST['mail2']) AND !empty($_POST['mdp']) AND !empty($_POST['mdp2'])) {[/PHP][/SPOILER] [CENTER][SIZE=3]Premièrement nous vérifions si l'utilisateur [B][COLOR=#0059b3]à cliqué sur le bouton "submit"[/COLOR][/B] puis nous sécurisons grâce à un "[B][COLOR=#0059b3]htmlspecialchars[/COLOR][/B]" qui sert à faire en sorte que si l'utilisateur est méchant et essaye de rentrer du code, [B][COLOR=#0059b3]son code sera prit en texte plein[/COLOR][/B], c'est utile surtout si il y a un système de profil car si un utilisateur gentil va sur son profil, [B][COLOR=#0059b3]il aura le code écris et non exécuté, trim sert à enlever les espaces vides.[/COLOR][/B] Vous allez me dire qu'il n'y a pas de "htmlspecialchars" mais "sha1" devant le mot de passe, c'est normal car nous [B][COLOR=#0059b3]ne voulons pas voir les mots de passes de vos membres[/COLOR][/B], nous voulons que leurs mots de passes soient sur de ne pas être volé si un hackeur accède à votre base de donnée, donc nous [B][COLOR=#0059b3]les cryptons[/COLOR][/B] grâce à cette fonction, il existe aussi [B][COLOR=#0059b3]la fonction "md5" mais elle est moins sur[/COLOR][/B], la toute première ligne de ce spoiler est [B][COLOR=#0059b3]la connexion à la base de donnée[/COLOR][/B]. [IMG]https://reality-gaming.fr/attachments/djamel4-png.61409/[/IMG] Maintenant nous allons vérifier si[B][COLOR=#0059b3] les deux emails et les deux mots de passes que l'utilisateur a rentré sont identiques[/COLOR][/B], et si l'adresse mail est [B][COLOR=#0059b3]correcte[/COLOR][/B], c'est à dire si l'adresse mail comporte bien un @ et la fin en .fr (ou .com...). [SPOILER="2ème vérification"] [PHP] $pseudolength = strlen($pseudo)if($pseudolength <= 25) { if($mail == $mail2) { if(filter_var($mail, FILTER_VALIDATE_EMAIL)) { $reqmail = $bdd->prepare("SELECT * FROM membres WHERE mail = ?"); $reqmail->execute(array($mail)); $mailexist = $reqmail->rowCount(); if($mailexist == 0) { if($mdp == $mdp2) {[/PHP][/SPOILER] [CENTER][SIZE=3][SIZE=3][SIZE=3][SIZE=3]Donc la nous allons calculer la longueur du pseudo grâce à une fonction "[B][COLOR=#0059b3]strlen[/COLOR][/B]", si le pseudo est [B][COLOR=#0059b3]inférieur ou égale à 25 caractères[/COLOR][/B], nous passons [B][COLOR=#0059b3]à la deuxième vérification[/COLOR][/B] qui vérifie si les deux emails que l’utilisateur correspondent, si ils correspondent [B][COLOR=#0059b3]nous passons à l'étape suivante[/COLOR][/B] qui vérifie si le mail est bon, [B][COLOR=#0059b3]je vous ai expliqué plus haut[/COLOR][/B], si le mail est bon nous vérifions si l'email n'existe pas déjà, si "[B][COLOR=#0059b3]$mailexist[/COLOR][/B]" est égale à 0, ce qui veut dire que l'email [B][COLOR=#0059b3]n'est pas dans la base de donnée[/COLOR][/B], nous passons à [B][COLOR=#0059b3]la dernière étape de vérification[/COLOR][/B], nous vérifions si les deux mots de passe correspondent, si ils correspondent bien [B][COLOR=#0059b3]nous insérons dans la base de donnée[/COLOR][/B].[/SIZE][/SIZE][/SIZE][/SIZE][/CENTER] [SPOILER="L’insertion dans la base de donnée"] [PHP] $insertmbr = $bdd->prepare("INSERT INTO membres(pseudo, mail, motdepasse) VALUES(?, ?, ?)");$insertmbr->execute(array($pseudo, $mail, $mdp));} [/PHP][/SPOILER] [/SIZE] [CENTER][SIZE=3][SIZE=3][SIZE=3][SIZE=3]Nous avons fait toutes les étapes de vérifications puis l’insertion dans la base de donnée. Nous allons [B][COLOR=#0059b3]mettre des messages d'erreurs[/COLOR][/B] si, par exemple, l’utilisateur rentre 26 caractères, alors il aura[B][COLOR=#0059b3] un message[/COLOR][/B] sous le formulaire qui lui dis que [B][COLOR=#0059b3]la taille maximum est de 25 caractères[/COLOR][/B]. Vous n'avez qu'à copier-coller en dessous de [B][COLOR=#0059b3]la requête SQL[/COLOR][/B] ce qui se trouve dans le SPOILER [B][COLOR=#0059b3]ci-dessous[/COLOR][/B].[/SIZE] [SPOILER="Messages d'erreurs"] [PHP]else $erreur = "Vos mots de passes ne correspondent pas !"; } } else { $erreur = "Adresse mail déjà utilisée !"; } } else { $erreur = "Votre adresse mail n'est pas valide !"; } } else { $erreur = "Vos adresses mail ne correspondent pas !"; } } else { $erreur = "Votre pseudo ne doit pas dépasser 255 caractères !"; } } else { $erreur = "Tous les champs doivent être complétés !"; } }[/PHP][/SPOILER] [/SIZE] [CENTER][SIZE=3][SIZE=3][SIZE=3][SIZE=3][SIZE=3]Et en dessous de la[B][COLOR=#0059b3] fermeture de la balise "form" [/COLOR][/B]en dessous de votre page nous [B][COLOR=#0059b3]allons affiché l'erreur[/COLOR][/B]. [/SIZE][/SIZE] [SPOILER="Affichage de l'erreur"][PHP]<?php if(isset($erreur)) { echo $erreur; } ?>[/PHP][/SPOILER] Et voila :RG: c'est la fin de [B][COLOR=#0059b3]cette première partie[/COLOR][/B], si vous avez un problème ou une question n'hésitez pas à [B][COLOR=#0059b3]m'envoyer un message privée en expliquant votre soucis[/COLOR][/B]. :tchuss:[/SIZE][/SIZE][/SIZE][/CENTER][/SIZE][/SIZE][/CENTER][/CENTER][/SIZE][/CENTER] [/QUOTE]
Insérer les citations…
Vérification
Publier la réponse
Forums
Forums généraux
Informatique
Développement
#1 Créer un espace membre | Inscription
Ce site utilise des cookies. En continuant à utiliser ce site, vous acceptez l'utilisation des cookies.
Acceptez
En savoir plus.…
Haut