Guest User

Untitled

a guest
Mar 24th, 2013
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.97 KB | None | 0 0
  1. <?php
  2. require('inc/config.inc.php');
  3. require('inc/session.inc.php');
  4. include('inc/functions.inc.php');
  5. ?>
  6.  
  7. <html>
  8. <h1>Recover</h1>
  9. <br />
  10.  
  11.  
  12. <form action="recover.php" method="POST">
  13.     Your name: <input type="text" name="username"><br />
  14.     Password for this recover: <input type="password" name="password"><br />
  15.     Your Message: <input type="text" name="message"><br />
  16.     <input type="submit" name="submit"><br />
  17. </form>
  18.  
  19. <?php
  20.     if (!isset($_GET['recovery'])) {
  21.         // Check if isset, also fixes the php notices error.
  22.         if (isset($_POST['username']) && isset($_POST['password']) && isset($_POST['message'])) {
  23.             // Created shortcuts for the POSTs we currently have.
  24.             $username = $_POST['username'];
  25.             $password = $_POST['password'];
  26.             $message = $_POST['message'];
  27.         }
  28.        
  29.         /* Error checking */
  30.         // Filling up the errors array, if there's an error so you can call it after.
  31.        
  32.             $errors = array();
  33.            
  34.             if (empty($username)) {
  35.                 $errors[] = 'Username is empty';
  36.             }
  37.             else if (empty($password))
  38.             {
  39.                 $errors[] = 'Password is empty';
  40.             }
  41.             else if (strlen($username) > 11)
  42.             {
  43.                 $errors[] = 'Your username is more than 11 characters long';
  44.             }
  45.        
  46.         // This checks if variabes are not empty, and if username is less than 11 characters long.
  47.         if (!empty($username) && !empty($password) && !empty($message) && strlen($username) < 11) {
  48.        
  49.             // Shortcut for our ID generator function.
  50.             $ID = generateID();
  51.            
  52.             // Now lets insert (register the account) these datas to our database.
  53.             $insert = $connect->prepare(
  54.             "INSERT INTO users (
  55.                 username,
  56.                 password,
  57.                 message,
  58.                 date,
  59.                 time,
  60.                 id
  61.             ) VALUES (
  62.                 :username,
  63.                 :password,
  64.                 :message,
  65.                 CURDATE(),
  66.                 CURTIME(),
  67.                 :id
  68.             )");
  69.            
  70.             // Executing in array, because if we binded all these variables, it would look very bad.
  71.             if( !$insert->execute(array(
  72.                 ':username' => $username,      
  73.                 ':password' => $password,
  74.                 ':message' => $message,
  75.                 ':id' => $ID)) ) {
  76.  
  77.                     // Let's see if there's an error.
  78.                     print_r($insert->errorInfo());
  79.             }
  80.             // Let's store these into a session now.
  81.             $_SESSION['user'] = $username;
  82.             $_SESSION['pass'] = $password;
  83.            
  84.             //Now let's refresh the page, to a different header.
  85.             header('Location: recover.php?recovery=success');
  86.         }
  87.        
  88.         // Let's check if errors is not empty.
  89.         else if (!empty($errors))
  90.         {
  91.             // Now let's use a loop to get all of the error messages set in the array.
  92.             foreach ($errors as $error) {
  93.                 echo $error;
  94.             }
  95.         }
  96.     else if (isset($_GET['recovery']) && $_GET['recovery'] == 'success')
  97.     {
  98.     echo $_SESSION['user'];
  99.    
  100.         /*
  101.        
  102.         ***REMOVED FOR TESTING***
  103.        
  104.         $fetch = $connect->query("SELECT * FROM users WHERE username = ':username' LIMIT 1");
  105.         $fetch->bindValue(':username', $_SESSION['user']);
  106.         $fetch->execute();
  107.        
  108.         while($row = $fetch->fetch( PDO::FETCH_ASSOC )) {
  109.             echo $row['recover_id'];
  110.         }
  111.         */
  112.     }
  113. }
  114. ?>
  115. </html>
Advertisement
Add Comment
Please, Sign In to add comment