Jump to content

Password Protect A Register Page


ChidoriSoul

Recommended Posts

Ok, so I just finished my Register page, but I don't want anyone to register yet, so I need to password protect the page, where people have to enter the correct passcode to make the registration process work.Anyone know how to do it?

Link to comment
Share on other sites

Why don't you just use .htaccess to limit the people that can access the page by IP?

Link to comment
Share on other sites

Password protected seems a bit much work for something that you are going to unveil anyway.Why don't you: use Synook's suggestion. use CSS: form{display:none;} or form{visibility:hidden;}, this way no one can see the form and submit anything, (unless they view page source or edit it with firebug or similar) place html comments around it (same issue as above), or place php comments around the form output so the html code is never sent. make another input element, and in your php register code, if that value is not equal to a certain number or string, then don't run php register code. Kind of like a captcha or anti-spam for comments...OK, just re-read your post...

...where people have to enter the correct passcode to make the registration process work.
...so it sounds like you don't want just anybody to be able to register, but maybe have people with passwords so they can test it out or something??Anyway, if you don't want to use any suggestions above. Here's some really basic code.On your register page, add this inside a php block (adjust php delimiters accordingly). <?phpif(empty($password)){ $password = '';}if($password == '' && isset($_POST['p'])){ $password = md5($_POST['p']);}else{ $password = '';}if($password == '5f4dcc3b5aa765d61d8327deb882cf99'){ //register code in here.}else{ ?> <form action="" method="post"> <input type="password" name="p" /> <input type="submit" value="Log in" /> </form> <?php}?>OR<?phpif(empty($password)){ $password = '';}if($password == '' && isset($_POST['p'])){ $password = md5($_POST['p']);}else{ $password = '';}if($password != '5f4dcc3b5aa765d61d8327deb882cf99') //md5('password');{ header("Location: http://yourwebsite.com/some-other-page.php"); exit; // no code should run after redirect.}?>[/code]The second code allows you to place it above the register code, and not worry about anything else, whereas the first one you should paste your register code inside the corresponding braces.And if you wanted, change all $_POST variables to $_GET, and change the method of the form to "get", and this way you could bookmark the page so you don't have to type in the password all the time. Only downfall is the password is in clear text in the url.
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...