26

Re: register.php and require/include

Cool stuff. Will make it the original mod even easier to admin.

MattF: can you now post an authoritative version of your modifications?

It is a bit hard to track from all of the above (at least for a simple peasant like me) what goes where and when smile

27

Re: register.php and require/include

No probs. big_smile I'll post the final complete working version in this thread, and then it's all yours to do with as you will. big_smile I was just scratching an itch. (I hate been beaten). big_smile

28 (edited by MattF 2007-06-11 20:57)

Re: register.php and require/include

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. big_smile (Or enclode them within php start/end tags if you want to keep them). If you've any probs, give us a shout. big_smile 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. big_smile 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. big_smile


Have fun,

Matt

29

Re: register.php and require/include

Excellent. I'm sure that will be very handy for many people.

30

Re: register.php and require/include

sirena wrote:

Excellent. I'm sure that will be very handy for many people.

I'm just surprised Smartys managed to resist throttling me with all the questions I asked. big_smile big_smile Thanks again for all your help btw Smartys. smile smile