Guest User

Untitled

a guest
Jan 24th, 2011
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if(!empty($_SESSION['membre']))
  4. {
  5. header('Location: index.php');
  6. }
  7.  
  8. ini_set('display_errors', 1);
  9.  
  10. if(!empty($_POST))
  11. {
  12. extract($_POST);
  13. $valid = true;
  14.  
  15.  
  16. if(empty($nom))
  17. {
  18. $valid = false;
  19. $erreurnom = 'indiquez votre nom';
  20. }
  21.  
  22. if(!empty($nom) && strlen($nom)<3)
  23. {
  24. $valid = false;
  25. $erreurnom = '3 caractères minimum';
  26. }
  27. if(empty($email))
  28. {
  29. $valid = false;
  30. $erreuremail = 'Indiquez votre e-mail';
  31. }
  32.  
  33. if (!empty($email) && filter_var($email,FILTER_VALIDATE_EMAIL)===FALSE)
  34. {
  35. $valid = false;
  36. $erreuremail = 'Adresse e-mail invalide';
  37. }
  38.  
  39.  
  40. try{
  41. $bdd = new PDO('mysql:host=localhost;dbname=teamcom_team420' , 'teamcom_test', 'test') or die(print_r($bdd->errorInfo()));
  42. $bdd->exec('SET NAMES utf8');
  43. }
  44. catch(Exeption $e){
  45. die('Erreur:'.$e->getMessage());
  46. }
  47.  
  48. $req = $bdd->prepare('SELECT id from pts_membre WHERE login=:nom');
  49. $req->execute(array(':nom'=>$nom));
  50. if($req->rowCount()>0)
  51. {
  52. $valide = false;
  53. $erreurid = 'Pseudo déjà utilisé';
  54. }
  55.  
  56. $req = $bdd->prepare('SELECT id from pts_membre WHERE email=:email');
  57. $req->execute(array(':email'=>$email));
  58. if($req->rowCount()>0)
  59. {
  60. $valide = false;
  61. $erreurid = 'E-mail déjà utilisé';
  62. }
  63. $req->closeCursor();
  64.  
  65. if($valid)
  66. {
  67. $hash = md5(rand(0,1000));
  68. $pass = rand(1000,5000);
  69.  
  70. $to = $email;
  71. $subject = 'Inscription|Validation';
  72. $message = 'Merci pour votre inscription !<br />
  73. Vous pourrez vous connecter sur le site après avoir cliqué sur le lien d\'activation.<br />
  74. Voici vos identifiants, nous vous recommandons de changer le mot de passe.<br />
  75. Login : '.$nom.'<br />
  76. Mot de pass : '.$pass.'<br />
  77.  
  78. Lien \'activation :<br />
  79. <a href="http://www.420-team.com/PTS/verif.php?email=' .$email. '$hash=' .$hash. '">http://www.420-team.com/PTS/verif.php?email=' .$email. '$hash=' .$hash. '</a>';
  80.  
  81. $headers = 'From:[email protected]'."\r\n";
  82. $headers.='MIME-version: 1.0'."\r\n";
  83. $headers.='Content-type: text/html; charset=utf-8' ."\r\n";
  84. mail($to,$subject,$message,$headers);
  85.  
  86. $req = $bdd->prepare('INSERT INTO pts_membre (login,pass,email,hash) VALUES (:nom,:pass,:email,:hash)');
  87. $req->execute(array(
  88. 'nom'=>$nom,
  89. 'pass'=>sha1($pass),
  90. 'email'=>$email,
  91. 'hash'=>$hash,
  92. ));
  93.  
  94. $req->closeCursor();
  95. $ok = 'inscription réussie, vous allez recevoir un e-mail de confirmation';
  96. unset($nom);
  97. unset($email);
  98. }
  99.  
  100. }
  101. ?>
  102. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  103. <html xmlns="http://www.w3.org/1999/xhtml">
  104. <head>
  105. <title>En construction</title>
  106. <link rel="stylesheet" type="text/css" href="css/default.css" />
  107. <!--[IF IE]><link rel="stylesheet" type="text/css" href="css/default-ie.css" /><![EndIf]-->
  108. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  109. </head>
  110. <body>
  111. <div id="header">
  112. <div id="head-content">
  113. <div id="logo">Logo du site</div>
  114. <div id="menu">
  115. <ul>
  116. <li>Accueil</li>
  117. <li>Lien</li>
  118. <li>Lien</li>
  119. <li>Lien</li>
  120. </ul>
  121. </div>
  122. </div>
  123. </div>
  124. <div id="main">
  125. <div id="site">
  126. <div id="content">
  127. <div>
  128. <? if(isset($erreurid)) echo '<div class="erreurid"><p>' .$erreurid. '</p></div>' ;?>
  129. <? if(isset($ok)) echo '<div class="ok"><p>' .$ok. '</p></div>' ;?>
  130. </div>
  131. <div id="title-page"><h3>Devenez-membre</h3></div>
  132.  
  133. <form action="inscription.php" method="post">
  134. <label for="nom">Nom :</label>
  135. <input type="text" name="nom" value="<? if(isset($nom)) echo $nom ?>" />
  136. <div class="error"><? if(isset($erreurnom)) echo $erreurnom; ?></div>
  137.  
  138. <label for="email">Votre E-mail :</label>
  139. <input type="text" name="email" value="<? if(isset($email)) echo $email ?>" />
  140. <div class="error"><? if(isset($erreuremail)) echo $erreuremail; ?></div>
  141.  
  142. <input type="submit" class="submit-envoyer" value="Envoyer !" />
  143. </form>
  144.  
  145. <p><a href="index.php">Revenir à l'accueil</a></p>
  146.  
  147. <?php
  148. error_reporting(E_ALL);
  149. ini_set("display_errors", 1);
  150. include("file_with_errors.php");
  151. ?>
  152. </div>
  153. <div id="right">
  154. <div id="login-title" class="center-right"><h2>Espace Membre</h2></div>
  155. <div id="login" class="center-right">
  156. <?php
  157. if(empty($_SESSION['membre']))
  158. { ?>
  159. <h2>Bonjour et bienvenue</h2>
  160. <p>Pour vous inscrire, c'est <a href="inscription.php">ici</a>.</p>
  161. <p>Sinon <a href="login.php">connectez-vous</a>.</p>
  162. <? }
  163. else
  164. { ?>
  165. <h2>Bonjour <? echo $_SESSION['membre']; ?>, ravis de te revoir !</h2>
  166. <p>Va personnaliser <a href="profil.php">ton profil</a>.</p>
  167. <? } ?>
  168. </div><!-- END #login -->
  169. </div><!-- END #right -->
  170. </div>
  171. </div>
  172. <div id="footer">&nbsp;</div>
  173. </body>
  174. </html>
Advertisement
Add Comment
Please, Sign In to add comment