Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Password Protected Page
#1
Anyone have any ideas for how to create a password protected page? Or possibly a redirect to a "hidden" page (not listed in the menu)? or a Plugin?

thanks!
Reply
#2
Hey,

This is how I did it on one of my sites, needed some quick and easy.
You'll need Customfields plugin installed... setup a new field as a dropdown with one option"protected"
and a second textfield called "password"


Change your template file where you echo the page content to

Code:
if (returnCustomField('pagetype')=="protected"){
                include "protected.php";
            }
             else {
                get_page_content();
            }

The content of protected.php is

Code:
<?php

$password=(isset($_POST['password']) && $_POST['password']!= '') ? $_POST['password'] : '';
$realPassword=returnCustomField('password');
$err="";

if ($password!="" && $password!=$realPassword){
    $err="Password Incorrect";
}

if ($password==$realPassword){

get_page_content();
    
} else {


?>
<div style="text-align:center;"><br/> <br/>
<h2 style="margin-right:0px;">Welcome to the VIP area.</h2>
<br/>

<br/>
<form action="index.php?id=vip" method="post">
Please enter your Password:
<br/> <br/>
<input type="password" name="password" id="password"  /><br/>
<input type="submit" value="Enter" />
</form>
<?php
if ($err){
    echo "<p class='passFail'>".$err."</p>";    
}
?>

</div>

<?php
}
?>



Could probably be coded a lot better but he needed something fast and this works for him...

Hope it helps...

Mike....
My Github Repos: Github
Website: DigiMute
Reply
#3
n00dles101 Wrote:Hope it helps...

As ever, awesome! Thanks - will try it out.
Reply




Users browsing this thread: 1 Guest(s)