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.18 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.         setcookie('username', $username, $expiry->getTimestamp());
  15.     }
  16.     if(empty($_POST['password']))
  17.     {
  18.         $errors[] = "Password is empty!";
  19.     }
  20.     else
  21.     {
  22.         $password = $_POST['password'];
  23.         setcookie('password', $password, $expiry->getTimestamp());
  24.     }
  25.    
  26.     $expiry = new Datetime('+1 year');
  27.    
  28.    
  29.     echo $_COOKIE['username'].", ".$_COOKIE['password'];
  30. }
  31. ?>
  32. <form action="#" method="post">
  33.     <label for="username">Username: </label><input type="text" name="username"><br />
  34.     <label for="password">Password: </label><input type="text" name="password"><br />
  35.     <input type="submit" name="submit" value="Submit">
  36. </form>
  37. <div class="parent">
  38.     <?php
  39.         if(!empty($_COOKIE)) {
  40.             echo $_COOKIE['username'].", ".$_COOKIE['password'];
  41.         }
  42.         else {
  43.             echo "<ul>"
  44.             foreach($errors as $error)
  45.             {
  46.                 echo "<li>".$error."</li>";
  47.             }
  48.             echo "</ul>";
  49.         }
  50.     ?>
  51. </div>
  52. <style>
  53.     .parent {
  54.         background-color: red;
  55.         width: 500px;
  56.         height: 500px;
  57.         text-align: center;
  58.         line-height: 500px;
  59.     }
  60. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement