Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ###############################################################
- # Page Password Protect 2.13
- ###############################################################
- # Visit http://www.zubrag.com/scripts/ for updates
- ###############################################################
- #
- # Usage:
- # Set usernames / passwords below between SETTINGS START and SETTINGS END.
- # Open it in browser with "help" parameter to get the code
- # to add to all files being protected.
- # Example: password_protect.php?help
- # Include protection string which it gave you into every file that needs to be protected
- #
- # Add following HTML code to your page where you want to have logout link
- # <a href="http://www.example.com/path/to/protected/page.php?logout=1">Logout</a>
- #
- ###############################################################
- /*
- -------------------------------------------------------------------
- SAMPLE if you only want to request login and password on login form.
- Each row represents different user.
- $LOGIN_INFORMATION = array(
- 'zubrag' => 'root',
- 'test' => 'testpass',
- 'admin' => 'passwd'
- );
- --------------------------------------------------------------------
- SAMPLE if you only want to request only password on login form.
- Note: only passwords are listed
- $LOGIN_INFORMATION = array(
- 'root',
- 'testpass',
- 'passwd'
- );
- --------------------------------------------------------------------
- */
- ##################################################################
- # SETTINGS START
- ##################################################################
- // Add login/password pairs below, like described above
- // NOTE: all rows except last must have comma "," at the end of line
- $LOGIN_INFORMATION = array(
- 'reinhold',
- 'habekeinpasswort',
- 'keinpasswort',
- );
- // request login? true - show login and password boxes, false - password box only
- define('USE_USERNAME', false);
- // User will be redirected to this page after logout
- define('LOGOUT_URL', './');
- // time out after NN minutes of inactivity. Set to 0 to not timeout
- define('TIMEOUT_MINUTES', 20);
- // This parameter is only useful when TIMEOUT_MINUTES is not zero
- // true - timeout time from last activity, false - timeout time from login
- define('TIMEOUT_CHECK_ACTIVITY', true);
- ##################################################################
- # SETTINGS END
- ##################################################################
- ///////////////////////////////////////////////////////
- // do not change code below
- ///////////////////////////////////////////////////////
- // show usage example
- if(isset($_GET['help'])) {
- die('Include following code into every page you would like to protect, at the very beginning (first line):<br><?php include("' . str_replace('\\','\\\\',__FILE__) . '"); ?>');
- }
- // timeout in seconds
- $timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES * 60);
- // logout?
- if(isset($_GET['logout'])) {
- setcookie("verify", '', $timeout, '/'); // clear password;
- header('Location: ' . LOGOUT_URL);
- exit();
- }
- if(!function_exists('showLoginPasswordProtect')) {
- // show login form
- function showLoginPasswordProtect($error_msg) {
- ?>
- <html>
- <head>
- <title>PDEVDES // PLAYGROUND</title>
- <link rel="apple-touch-icon" sizes="180x180" href="favicon/apple-touch-icon.png">
- <link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
- <link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
- <meta http-equiv="cache-control" content="no-cache">
- <meta http-equiv="pragma" content="no-cache">
- <link href="css/font-face/roboto-regular/roboto-regular.css" rel="stylesheet">
- <link href="css/animate.min.css" rel="stylesheet">
- <link href="css/meyerreset.css" rel="stylesheet">
- <link href="css/normalize.css" rel="stylesheet">
- <link href="css/style.css" rel="stylesheet">
- <style>
- *, *:before, *:after {
- box-sizing:border-box;
- margin:0;
- }
- html {
- }
- body {
- background:#282a36;
- color:#d3d7cf;
- font-family:'Roboto', sans-serif;
- font-size:1em;
- }
- #login {
- border-radius: 8px;
- background: #999;
- border: 1px solid #111;
- color: #111;
- margin: 20% auto auto;
- max-width: 500px;
- padding: 10px
- }
- #errormsg,input {
- padding: 10px;
- width: 100%
- }
- #errormsg,input,label {
- color: #fff;
- display: block
- }
- #errormsg {
- background: #c00;
- position: absolute;
- text-align: center;
- top: 0
- }
- input,label {
- margin: 0 0 5px
- }
- input {
- border: 1px solid #111;
- color: #2e3436
- }
- input[type=input],input[type=password] {
- background: #c1c1c1;
- transition: .5s
- }
- input[type=input]:focus,input[type=password]:focus {
- background: #dcdcdc
- }
- input[type=submit] {
- background: #6e6e6e;
- color: #eee;
- display: block;
- margin: 0 0 5px;
- width: 100%;
- transition: .5s
- }
- input[type=submit]:hover {
- background: #00bb25;
- color: #fff
- }
- ::-webkit-input-placeholder {
- color: #555753
- }
- :-ms-input-placeholder {
- color: #555753
- }
- ::placeholder {
- color: #555753
- }
- h3 {
- margin: 0 0 10px
- }
- </style>
- </head>
- <body>
- <?php echo $error_msg; ?>
- <div id="login">
- <h3>DEVDES // PLAYGROUND</h3>
- <form method="post">
- <?php if (USE_USERNAME) echo '
- <input type="input" name="access_login" placeholder="Username" onfocus="this.placeholder=\'\'" onblur="this.placeholder=\'Username\'" autocomplete="off"/>';?>
- <input type="password" name="access_password" placeholder="Password" onfocus="this.placeholder=''" onblur="this.placeholder='Password'" autocomplete="off"/>
- <input type="submit" name="Submit" value="LOGIN" />
- </form>
- </div>
- </body>
- </html>
- <?php
- // stop at this point
- die();
- }
- }
- // user provided password
- if (isset($_POST['access_password'])) {
- $login = isset($_POST['access_login']) ? $_POST['access_login'] : '';
- $pass = $_POST['access_password'];
- if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION)
- || (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) )
- ) {
- showLoginPasswordProtect('<div id="errormsg" class="animated infinite flash delay-2s">Incorrect password.</div>');
- }
- else {
- // set cookie if password was validated
- setcookie("verify", md5($login.'%'.$pass), $timeout, '/'); // Some programs (like Form1 Bilder) check $_POST array to see if parameters passed
- // So need to clear password protector variables
- unset($_POST['access_login']);
- unset($_POST['access_password']);
- unset($_POST['Submit']);
- }
- }
- else {
- // check if password cookie is set
- if (!isset($_COOKIE['verify'])) {
- showLoginPasswordProtect("");
- }
- // check if cookie is good
- $found = false;
- foreach($LOGIN_INFORMATION as $key=>$val) {
- $lp = (USE_USERNAME ? $key : '') .'%'.$val;
- if ($_COOKIE['verify'] == md5($lp)) {
- $found = true;
- // prolong timeout
- if (TIMEOUT_CHECK_ACTIVITY) {
- setcookie("verify", md5($lp), $timeout, '/');
- }
- break;
- }
- }
- if (!$found) {
- showLoginPasswordProtect("");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement