Advertisement
Guest User

Untitled

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