Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $errors = array();
- if(isset($_POST['submit']))
- {
- if(empty($_POST['username']))
- {
- $errors[] = "Username is empty!";
- }
- else
- {
- $username = $_POST['username'];
- setcookie('username', $username, $expiry->getTimestamp());
- }
- if(empty($_POST['password']))
- {
- $errors[] = "Password is empty!";
- }
- else
- {
- $password = $_POST['password'];
- setcookie('password', $password, $expiry->getTimestamp());
- }
- $expiry = new Datetime('+1 year');
- echo $_COOKIE['username'].", ".$_COOKIE['password'];
- }
- ?>
- <form action="#" method="post">
- <label for="username">Username: </label><input type="text" name="username"><br />
- <label for="password">Password: </label><input type="text" name="password"><br />
- <input type="submit" name="submit" value="Submit">
- </form>
- <div class="parent">
- <?php
- if(!empty($_COOKIE)) {
- echo $_COOKIE['username'].", ".$_COOKIE['password'];
- }
- else {
- echo "<ul>"
- foreach($errors as $error)
- {
- echo "<li>".$error."</li>";
- }
- echo "</ul>";
- }
- ?>
- </div>
- <style>
- .parent {
- background-color: red;
- width: 500px;
- height: 500px;
- text-align: center;
- line-height: 500px;
- }
- </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement