Advertisement
Guest User

Untitled

a guest
May 25th, 2018
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.87 KB | None | 0 0
  1.  if (isset($_POST['password']) && $_POST['password'] == 'MYPASS') { // We check here if the password entered matches 'MYPASS' and if so we set a cookie for 30 days.
  2.         setcookie("password", 'MYPASS', strtotime('+30 days'));
  3.         header('Location: '.$_SERVER['PHP_SELF']);
  4.         exit;
  5.     }
  6. if ($_GET['q'] !== 'VALUE'){ // Here we check if 'index.php?q' has a value of 'VALUE' and if not we ask for password.
  7.     // Simple password protection
  8.     if (!isset($_COOKIE['password']) || $_COOKIE['password'] !== 'MYPASS') {
  9.        echo' <html>
  10. <head>
  11.    <title>Password protected</title>
  12. </head>
  13. <body>
  14.    <div style="text-align:center;margin-top:50px;">
  15.        You must enter the password to view this content.
  16.        <form method="POST">
  17.            <input type="text" name="password">
  18.        </form>
  19.    </div>
  20. </body>
  21. </html>';
  22.         exit;
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement