Advertisement
Skorpius

Remember Me

Feb 2nd, 2023
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.66 KB | None | 0 0
  1. <?php
  2.  
  3.     //session_start();
  4.  
  5.     if(isset($_POST['submit'])){
  6.        
  7.         //Vars set as if user found in dbase
  8.         $userrow = 1;
  9.         $custid = 3;
  10.        
  11.        
  12.        
  13.         $uname             = $_POST['uname'];
  14.         $email             = $_POST['email'];
  15.        
  16.        
  17.         if($userrow>0)
  18.         {
  19.            
  20.             $_SESSION['user_id']=$custid;
  21.             if(!empty($_POST['remember_checkbox'])){
  22.                 $remember_checkbox = $_POST['remember_checkbox'];
  23.                
  24.                 //Set Cookie
  25.                 setcookie('username', $uname,time()+3600*24*7);
  26.                 setcookie('email', $email,time()+30);
  27.             }else{
  28.                
  29.                 //Expire the cookie
  30.                 setcookie('username', $uname,time()-3600);
  31.                 setcookie('email', $email,time()-3600);
  32.                
  33.             }
  34.             //Redirect to dashboard
  35.             header('Location: rememberme.php');
  36.            
  37.         }else{
  38.             echo "Invalid Login";
  39.         }
  40.        
  41.        
  42.     }
  43.  
  44. ?>
  45.  
  46.  
  47. <!DOCTYPE html>
  48. <html lang="en">
  49.   <head>
  50.     <meta charset="UTF-8">
  51.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  52.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  53.     <title>Remember Me</title>
  54.     <link rel="stylesheet" href="./style.css">
  55.     <link rel="icon" href="./favicon.ico" type="image/x-icon">
  56.     <style>
  57.         form {
  58.           border: 3px solid #f1f1f1;
  59.         }
  60.  
  61.         /* Full-width inputs */
  62.         input[type=text], input[type=email] {
  63.           width: 100%;
  64.           padding: 12px 20px;
  65.           margin: 8px 0;
  66.           display: inline-block;
  67.           border: 1px solid #ccc;
  68.           box-sizing: border-box;
  69.         }
  70.  
  71.         /* Set a style for all buttons */
  72.         button {
  73.           background-color: #04AA6D;
  74.           color: white;
  75.           padding: 14px 20px;
  76.           margin: 8px 0;
  77.           border: none;
  78.           cursor: pointer;
  79.           width: 100%;
  80.         }
  81.  
  82.         /* Add a hover effect for buttons */
  83.         button:hover {
  84.           opacity: 0.8;
  85.         }
  86.  
  87.         /* Extra style for the cancel button (red) */
  88.         .cancelbtn {
  89.           width: auto;
  90.           padding: 10px 18px;
  91.           background-color: #f44336;
  92.         }
  93.  
  94.         /* Center the avatar image inside this container */
  95.         .imgcontainer {
  96.           text-align: center;
  97.           margin: 24px 0 12px 0;
  98.         }
  99.  
  100.         /* Avatar image */
  101.         img.avatar {
  102.           width: 40%;
  103.           border-radius: 50%;
  104.         }
  105.  
  106.         /* Add padding to containers */
  107.         .container {
  108.           padding: 40px;
  109.         }
  110.  
  111.         /* The "Forgot password" text */
  112.         span.psw {
  113.           margin-left: 40%;
  114.           padding-top: 16px;
  115.           padding-bottom: 16px;
  116.         }
  117.  
  118.         /* Change styles for span and cancel button on extra small screens */
  119.         @media screen and (max-width: 300px) {
  120.           span.psw {
  121.             display: block;
  122.             float: none;
  123.           }
  124.           .cancelbtn {
  125.             width: 100%;
  126.           }
  127.         }
  128.     </style>
  129.   </head>
  130.   <body>
  131.     <main>
  132.         <div class="container">
  133.             <h1>Remember Me</h1>  
  134.            
  135.             <?php
  136.            
  137.                 print_r($_COOKIE);
  138.            
  139.             ?>
  140.        
  141.             <form action="rememberme.php" method="post" autocomplete="off">
  142.              
  143.  
  144.               <div class="container">
  145.                 <label for="uname"><b>Username</b></label>
  146.                 <input type="text" placeholder="Enter Username" name="uname" value="<?php if(isset($_COOKIE['username'])){echo $_COOKIE['username'];}; ?>">
  147.  
  148.                 <label for="psw"><b>Email</b></label>
  149.                 <input type="email" placeholder="Enter Your Email Address" name="email" value="<?php if(isset($_COOKIE['email'])){echo $_COOKIE['email'];}; ?>">
  150.  
  151.                 <button type="submit" name="submit">Login</button>
  152.                 <label>
  153.                   <input type="checkbox" checked="checked" name="remember_checkbox"> Remember me
  154.                 </label>
  155.               </div>
  156.  
  157.               <div class="container" style="background-color:#f1f1f1">
  158.                
  159.                 <span class="psw">Forgot <a href="#">password?</a></span>
  160.               </div>
  161.             </form>
  162.         </div>
  163.        
  164.         <?php
  165.            
  166.             //showSessions();
  167.             echo '<br><br>';
  168.            
  169.            
  170.         ?>
  171.        
  172.             <h1>Print_r</h1>
  173.             <?php print_r($_COOKIE); ?>
  174.     </main>
  175.    
  176.   </body>
  177. </html>
  178.  
  179.  
  180.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement