Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $my_username = "comp321";
- $my_password = "comp321_0910";
- $expire_period = time()+60*60;
- $login_success = false;
- if(isset($_POST['username'])){
- $username = $_POST['username'];
- $password = $_POST['password'];
- setcookie("login_success", false, $expire_period);
- if($username == $my_username && $password == $my_password){
- $login_success = true;
- setcookie("login_success", true, $expire_period);
- setcookie("login_time", date(DATE_COOKIE), $expire_period);
- header( "Location:".$_SERVER['PHP_SELF'] );
- exit();
- }
- }
- if(isset($_GET['logout'])){
- setcookie("login_success", '', time()-3600);
- setcookie("login_time", '', time()-3600);
- header( "Location:".$_SERVER['PHP_SELF'] );
- exit();
- }
- ?>
- <html>
- <body>
- <?php
- if(isset($_COOKIE['login_success'])){
- ?>
- You are already logged in successfully. <br><br>
- Your last login time is <?php echo $_COOKIE['login_time']; ?>.<br><br>
- <a href="<?php echo $_SERVER['PHP_SELF']; ?>?logout=1">Logout</a>
- <?php
- }else{
- ?>
- <form name="frm_login" method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
- <table width="300" border="0" cellspacing="5" cellpadding="5">
- <tr>
- <td>Username : </td>
- <td><input name="username" id="username" type="text"></td>
- </tr>
- <tr>
- <td>Password : </td>
- <td><input name="password" id="password" type="password"></td>
- </tr>
- <tr>
- <td> </td>
- <td><input type="submit" value="Login"></td>
- </tr>
- </table>
- </form>
- <?php
- if($login_success == false && isset($_POST['username'])){
- ?>
- <font color="#FF0000">
- <b>username or password incorrect!</b></font><br><br>
- <?php
- }
- ?>
- For testing: <br>
- username : <?=$my_username?><br>
- password : <?=$my_password?>
- <?php
- }
- ?>
- </body></html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement