Password protecting your categories
-
If you want to password protect a category in 1.22 Kubrick, do the following:
1. In index.php above everything else add:
<?
session_start();if (!session_is_registered("password"))
{
$cart=array();
session_register("password");
}if ($_POST["txtPassword"]) $password=$_POST["txtPassword"];
$secretpassword = "yoursecretpassword";
?>2. In the above code, change
yoursecretpassword
to your desired password.3. In index.php (in the Begin Archives area), between:
<div id="content" class="narrowcolumn">
<?php if ($posts) { ?>
add:
<?php
if (($_GET["cat"] == 2 || $_GET["cat"] == 6 || $_GET["category_name"] == "passwordedcat2" || $_GET["category_name"] == "passwordedcat6") && ($password != $secretpassword))
{
//This is where the login form goes
echo "
<form name="form" method="post" action="";
echo $_SERVER["PHP_SELF"]."?".$_SERVER["QUERY_STRING"];
echo ""><b>Password:</b>
<input type="password" title="Enter your password" name="txtPassword" /><input type="submit" name="Submit" value="Login" />
</form>
";
}
else
{?>4. You might want to change passwordedcatx to your category name.
Maybe someone can make a plugin of this if there isn’t one yet. You might want to combine this with Kitten’s Show Categories plugin to prevent passworded categories from showing up on the main page.
YoB
- The topic ‘Password protecting your categories’ is closed to new replies.