SHARE
TWEET

Untitled

a guest May 27th, 2018 97 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. //Structura Database
  4. //DB: users
  5. //user_id INT(24) NOT NULL AUTO_INCREMENT
  6. //username VARCHAR(12) NOT NULL
  7. //password VARCHAR(10) NOT NULL
  8.  
  9. if(isset($_POST['submit'])){
  10.  
  11. $errors = array();
  12.  
  13.     if(isset($_POST['username']))
  14.     {
  15.         if(strlen($_POST['username']) < 2)
  16.         {
  17.             $errors[] = 'The username cannot be longer than 30 characters.<br /><a href="register.php">Back</a><br />';
  18.         }
  19.         if(strlen($_POST['username']) > 10)
  20.         {
  21.             $errors[] = 'The username cannot be longer than 10 characters.<br /><a href="register.php">Back</a><br />';
  22.         }
  23.  
  24.     }
  25.     else
  26.     {
  27.         $errors[] = 'The username field must not be empty.';
  28.     }
  29.    
  30.    
  31.     if(isset($_POST['password']))
  32.     {
  33.         if($_POST['password'] != $_POST['checkpassword'])
  34.         {
  35.             $errors[] = 'The two passwords did not match.<br /><a href="register.php">Back</a><br />';
  36.         }
  37.     }
  38.     else
  39.     {
  40.         $errors[] = 'The password field cannot be empty.<br /><a href="register.php">Back</a><br />';
  41.     }
  42.    
  43.  if(!empty($errors))
  44.     {
  45.         foreach($errors as $key => $value)
  46.         {
  47.             echo  $value;
  48.         }
  49.     }
  50.     else
  51.     {
  52.  
  53.     $dbuser = $_POST['username'];
  54.  
  55.     $tabela_utilizator = $dbuser.'_table';
  56.     $table = "CREATE TABLE $tabela_utilizator IF NOT EXISTS(
  57.    user_id INT(24) NOT NULL AUTO_INCREMENT,
  58.    username VARCHAR(12) NOT NULL,
  59.    password VARCHAR(10) NOT NULL
  60.    )";
  61.  
  62.     $sqlq = mysql_query($table);
  63.     if(!$sqlq){
  64.     print 'Table can&prime;t be created';
  65.     }else{
  66.     $sql = "INSERT INTO $tabela_utilizator(username, password) VALUES('" . mysql_real_escape_string($_POST['username']) . "','" . md5($_POST['password']) . "')";
  67.     $insert = mysql_query($sql);
  68.     print 'Utilizator inregistrat cu succes.';
  69.     }
  70.  
  71.   }
  72.  
  73.  
  74. }else{
  75.  
  76. print '
  77. <form action="" method="POST">
  78. <input type="text" name="username" size="21">
  79. <input type="password" name="password" size="21">
  80. <input type="password" name="checkpassword" size="21">
  81. <input type="submit" name="submit" value="Inregistreaza cont">
  82. </form>
  83. ';
  84.  
  85. }
  86. ?>
  87.  
  88.  
  89. Sign in(logare)
  90.  
  91. <?php
  92.  
  93. if(isset($_SESSION['logat']) && $_SESSION['logat'] == true)
  94. {
  95.     echo 'Esti deja logat,te poti  <a href="signout.php">deloga</a> daca vrei.';
  96.    
  97.  
  98. }
  99. else
  100. {
  101.  
  102. if($_SERVER['REQUEST_METHOD'] != 'POST')
  103.     {
  104.         /*the form hasn't been posted yet, display it
  105.           note that the action="" will cause the form to post to the same page it is on */
  106.         echo '<form method="post" action="">
  107.                <input type="text" name="username" size="21">
  108.                <input type="password" name="password" size="21">
  109.                <input type="submit" name="submit" value="Inregistreaza cont">
  110.         <input type="submit" value="Sign in" />
  111.          </form>';
  112.     }
  113.     else
  114.     {
  115.         $errors = array();
  116.        
  117.         if(empty($_POST['username']))
  118.         {
  119.             $errors[] = 'Campul userului este gol.';
  120.         }
  121.        
  122.         if(empty($_POST['password']))
  123.         {
  124.             $errors[] = 'Campul parola este gol.';
  125.         }
  126.        
  127.         if(!empty($errors))
  128.         {
  129.             echo 'Cateva probleme la logare<br /><br />';
  130.             echo '<ul>';
  131.             foreach($errors as $key => $value)
  132.             {
  133.                 echo '<li>' . $value . '</li>';
  134.             }
  135.             echo '</ul>';
  136.         }
  137.         else
  138.         {
  139.             //the form has been posted without errors, so save it
  140.             //notice the use of mysql_real_escape_string, keep everything safe!
  141.             //also notice the sha1 function which hashes the password
  142.             $sql = "SELECT
  143.                         user_id,
  144.                         username,
  145.                         password
  146.                     FROM
  147.                         users
  148.                     WHERE
  149.                         username = '" . mysql_real_escape_string($_POST['username']) . "'
  150.                     AND
  151.                         password = '" . md5($_POST['password']) . "'";
  152.                        
  153.             $result = mysql_query($sql);
  154.             if(!$result)
  155.             {
  156.  
  157.                 echo 'ERROR.';
  158.                 /
  159.             }
  160.             else
  161.                 if(mysql_num_rows($result) == 0)
  162.                 {
  163.                     echo 'Ai incercat gresit o combinatie de user si parola.Incearca mai tarziu.';
  164.                 }
  165.                 else
  166.                 {
  167.                     $_SESSION['logat'] = true;
  168.  
  169.                     while($row = mysql_fetch_assoc($result))
  170.                     {
  171.                         $_SESSION['user_id']    = $row['user_id'];
  172.                         $_SESSION['username']   = $row['username'];
  173.                     }
  174.  
  175.                        echo 'Bine ai venit, ' . $_SESSION['username'] . '. <br /><a href="index.php">Dute la pagina index.</a>.';
  176.                 }
  177.             }
  178.         }
  179.     }
  180.    
  181.  }
  182. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top