Advertisement
Guest User

Untitled

a guest
Jul 6th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.24 KB | None | 0 0
  1. <?php
  2.  
  3. $errors = array();
  4. if(isset($_POST['submit']))
  5. {
  6.    
  7.     if(empty($_POST['username']))
  8.     {
  9.         $errors[] = "Username is empty!";
  10.     }
  11.     else
  12.     {
  13.         $username = $_POST['username'];
  14.        
  15.        
  16.     }
  17.     if(empty($_POST['password']))
  18.     {
  19.         $errors[] = "Password is empty!";
  20.     }
  21.     else
  22.     {
  23.         $password = $_POST['password'];
  24.        
  25.        
  26.     }
  27.    
  28.     if(!empty($username) && !empty($password))
  29.     {
  30.         $expiry = new Datetime('+1 year');
  31.         setcookie('username', $username, $expiry->getTimestamp());
  32.         setcookie('password', $password, $expiry->getTimestamp());
  33.     }
  34. }
  35. ?>
  36. <form action="#" method="post">
  37.     <label for="username">Username: </label><input type="text" name="username"><br />
  38.     <label for="password">Password: </label><input type="text" name="password"><br />
  39.     <input type="submit" name="submit" value="Submit">
  40. </form>
  41. <div class="parent">
  42.     <?php
  43.         if(!empty($_COOKIE)) {
  44.             echo $_COOKIE['username'].", ".$_COOKIE['password'];
  45.         }
  46.         else {
  47.             echo "<ul>";
  48.             foreach($errors as $error)
  49.             {
  50.                 echo "<li>".$error."</li>";
  51.             }
  52.             echo "</ul>";
  53.         }
  54.     ?>
  55. </div>
  56. <style>
  57.     .parent {
  58.         background-color: red;
  59.         width: 500px;
  60.         height: 500px;
  61.         text-align: center;
  62.     }
  63.  
  64.     ul {
  65.         width: 500px;
  66.         height: 500px;
  67.         text-align: center;
  68.     }
  69. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement