This is the file include/user/register.php:
<?php
$register_failed = 'The answer you supplied was incorrect. Please try again.';
session_start();
if (!isset($_SESSION['answer']) || $_SESSION['answer'] == '')
{
$number = rand(1, 4); // Alter the second number to match the number of questions.
//---Questions array---//
$questions = array(
'q1' => 'One plus three equals?',
'q2' => 'Two plus four equals?',
'q3' => 'Eight plus eight equals?',
'q4' => 'Three times three equals?'
);
//-----Hints array-----//
$hints = array(
'h1' => 'One less than five',
'h2' => 'One more than five',
'h3' => 'Just under seventeen',
'h4' => 'One shy of ten'
);
//----Answers array----//
$answers = array(
'a1' => 'Four',
'a2' => 'Six',
'a3' => 'Sixteen',
'a4' => 'Nine'
);
$_SESSION['hint'] = $hints[h.$number];
$_SESSION['answer'] = $answers[a.$number];
$_SESSION['question'] = $questions[q.$number];
}
?>
The answers/questions/hints arrays can have as many added to as you like. Just remember to use the same prefix letter in each array:
(q, a, h), with the numbers after the letter rising sequentially.
The register.php file in the root forum directory needs the following:
This first addition is very near the top of the file.
if ($pun_config['o_regs_allow'] == '0')
{
require_once PUN_ROOT.'header.php';
message($lang_register['No new regs']);
}
require_once PUN_ROOT.'include/user/register.php'; // This line added
This is the second section in the root register.php file. The bits between the //----// need adding. I've included existing code above/below for placement. I think it goes in the same place as your original code:
else
{
$language = $pun_config['o_default_lang'];
}
//------------------------------------------------//
if (isset ($_POST['spamcode']) && $_POST['spamcode'] != '' && $_POST['spamcode'] == $_SESSION['answer'])
{
session_unset();
session_destroy();
}
else
{
session_unset();
session_destroy();
message("$register_failed");
}
//------------------------------------------------//
$timezone = round($_POST['timezone'], 1);
$save_pass = (!isset($_POST['save_pass']) || $_POST['save_pass'] != '1') ? '0' : '1';
This is the final section in the root register.php file. Again, layout as above, and goes in the same spot, (I think), as your original code:
<input type="text" name="req_email2" size="50" maxlength="50" /><br /></label>
<?php endif; ?> </div>
</fieldset>
</div>
//----------------------------------------------------//
<div class="inform">
<fieldset>
<legend>Spambot prevention question</legend>
<div class="infldset">
<p><b>Question:</b> <?php echo $_SESSION['question']; ?></p>
<p><b>Hint:</b> <?php echo $_SESSION['hint']; ?></p>
<input method="post" type="text" name="spamcode" size="10" maxlength="10"/><br/>
</div>
</fieldset>
</div>
//----------------------------------------------------//
<div class="inform">
<fieldset>
<legend><?php echo $lang_prof_reg['Localisation legend'] ?></legend>
Remember to remove those //----// lines from that last section as they're in a html section of the script. (Or enclode them within php start/end tags if you want to keep them). If you've any probs, give us a shout. I haven't put line numbers in btw because I do have a bad habit of severely altering/rewriting things, so my line numbers might be way out. I tested it around fifteen times with the final version, and it appeared to be behaving as it should. Obviously though, I would suggest giving it a good test on a test server before using it for real.
Have fun,
Matt