Topic: Presenting a Login form to all not-logged-in guests
In case anybody else is interested, I figured out a way to present not-logged-in guests with a login form instead of the message "You do not have permission to view these forums." This is assuming you don't want guests to be able to read the forums. Three simple steps:
1. If you haven't done so already, make sure to edit your PunBB 'groups' database so that the Guests row has a 'g_read_board' value of 0.
2. Open /index.php and go to line 32, and replace the contents of the line with
requiredlogin();
3. Add the following to the /include/functions.php file:
//
// Grand Purpose: To make forum "for members eyes only".
//
function requiredlogin()
{
global $db, $lang_common, $pun_config, $pun_start, $tpl_main;
require PUN_ROOT.'lang/English/login.php'; // replace 'English' with your default language of choice
if (!defined('PUN_HEADER'))
{
global $pun_user;
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Login'];
require PUN_ROOT.'header.php';
}
$redirect_url = (isset($_SERVER['HTTP_REFERER']) && preg_match('#^'.preg_quote($pun_config['o_base_url']).'/(.*?)\.php#i', $_SERVER['HTTP_REFERER'])) ? htmlspecialchars($_SERVER['HTTP_REFERER']) : 'index.php';
$page_title = pun_htmlspecialchars($pun_config['o_board_title']).' / '.$lang_common['Login'];
$required_fields = array('req_username' => $lang_common['Username'], 'req_password' => $lang_common['Password']);
$focus_element = array('login', 'req_username');
?>
<div class="blockform">
<h2><span><?php echo $lang_common['Login'] ?></span></h2>
<div class="box">
<form id="login" method="post" action="login.php?action=in" onsubmit="return process_form(this)">
<div class="inform">
<fieldset>
<legend><?php echo $lang_login['Login legend'] ?></legend>
<div class="infldset">
<input type="hidden" name="form_sent" value="1" />
<input type="hidden" name="redirect_url" value="<?php echo $redirect_url ?>" />
<label class="conl"><strong><?php echo $lang_common['Username'] ?></strong><br /><input type="text" name="req_username" size="25" maxlength="25" tabindex="1" /><br /></label>
<label class="conl"><strong><?php echo $lang_common['Password'] ?></strong><br /><input type="password" name="req_password" size="16" maxlength="16" tabindex="2" /><br /></label>
<p class="clearb"><?php echo $lang_login['Login info'] ?></p>
<p><a href="register.php" tabindex="4"><?php echo $lang_login['Not registered'] ?></a>
<a href="login.php?action=forget" tabindex="5"><?php echo $lang_login['Forgotten pass'] ?></a></p>
</div>
</fieldset>
</div>
<p><input type="submit" name="login" value="<?php echo $lang_common['Login'] ?>" tabindex="3" /></p>
</form>
</div>
</div>
<?php
require PUN_ROOT.'footer.php';
}
And thats it. I hope it isn't something that is brazenly obvious and I am a fool for pointing out. (I mean, it took me hours before this solution came to me.) Thanks PunBB team for creating such an awesome forum software. I'm going to have a lot of fun molding it to my needs.