Advertisement
Guest User

Untitled

a guest
Nov 5th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.77 KB | None | 0 0
  1. <?php
  2. //We check if the form has been sent
  3. if(isset($_POST['username'], $_POST['password'], $_POST['passverif'], $_POST['email'], $_POST['avatar']) and $_POST['username']!='')
  4. {
  5.     //We remove slashes depending on the configuration
  6.    
  7.         $_POST['username'] = stripslashes($_POST['username']);
  8.         $_POST['password'] = stripslashes($_POST['password']);
  9.         $_POST['passverif'] = stripslashes($_POST['passverif']);
  10.         $_POST['email'] = stripslashes($_POST['email']);
  11.         $_POST['avatar'] = stripslashes($_POST['avatar']);
  12.    
  13.     //We check if the two passwords are identical
  14.     if($_POST['password']==$_POST['passverif'])
  15.     {
  16.         //We check if the password has 6 or more characters
  17.         if(strlen($_POST['password'])>=6)
  18.         {
  19.             //We check if the email form is valid
  20.             if(preg_match('#^(([a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+\.?)*[a-z0-9!\#$%&\\\'*+/=?^_`{|}~-]+)@(([a-z0-9-_]+\.?)*[a-z0-9-_]+)\.[a-z]{2,}$#i',$_POST['email']))
  21.             {
  22.                 //We protect the variables
  23.                 $username = $pdo->quote($_POST['username']);
  24.                 $password = $pdo->quote($_POST['password']);
  25.                 $email = $pdo->quote($_POST['email']);
  26.                 $avatar = $pdo->quote($_POST['avatar']);
  27.                 //We check if there is no other user using the same username
  28.                 $stm = $pdo->query('SELECT id from users where username="'.$username.'"');
  29.                 $dn = $stm->rowCount();
  30.                 if($dn==0)
  31.                 {
  32.                     //We count the number of users to give an ID to this one
  33.                     $stm2 = $pdo->query('SELECT id from users');
  34.                     $dn2 = $stm2->rowCount();
  35.                     $id = $dn2+1;
  36.                     //We save the informations to the databse
  37.                     if($pdo->query('INSERT into users(id, username, password, email, avatar, signup_date) values ('.$id.', "'.$username.'", "'.$password.'", "'.$email.'", "'.$avatar.'", "'.time().'")'))
  38.                     {
  39.                         //We dont display the form
  40.                         $form = false;
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement