Location: PHPKode > projects > l2jweb > register.php
<?
$reg_msg = array("Please fill all the fileds.", "The passwords don't match.",
    "The security code is incorrect.", "The username already exists!",
    "The email adress it's already used!", "You must agree the Terms of Service!",
    "The email adress seems that is not valid!");
$error_reg = '';
if (($_GET['page'] == 'register') && (@$_POST['register'] == 'Submit'))
{
    //do reg procedure
    //verification
    if (@$_POST['passwd'] != $_POST['passwd2'])
        $error_reg .= "<br>" . $reg_msg[1];
    if ((@$_POST['passwd'] == '') || (@$_POST['passwd2'] == '') || (@$_POST['username'] ==
        '') || (@$_POST['email'] == ''))
        $error_reg .= "<br>" . $reg_msg[0];
    if (@$_POST['TOS'] != 'I agree')
        $error_reg .= "<br>" . $reg_msg[5];
    //if (@$_POST['sec_code']!=$_SESSION['security_code'])
    //$error_reg .="<br>".$reg_msg[2];
    //verify if account exists
    $sql_account_ex_register = "SELECT `login` FROM `accounts` WHERE `login`='" . $_POST['username'] .
        "'";
    $sql_account_ex_register_id = $db->query($sql_account_ex_register);
    if ($db->num_rows($sql_account_ex_register_id) != 0)
        $error_reg .= "<br>" . $reg_msg[3];
    else
    {
        $sql_account_ex_register = "SELECT * FROM `web_accounts` WHERE `username`='" . $_POST['username'] .
            "'";
        $sql_account_ex_register_id = $db->query($sql_account_ex_register);
        if ($db->num_rows($sql_account_ex_register_id) != 0)
            $error_reg .= "<br>" . $reg_msg[3];
        else
        {
            $sql_account_ex_register = "SELECT * FROM `web_accounts` WHERE `email`='" . $_POST['email'] .
                "'";
            $sql_account_ex_register_id = $db->query($sql_account_ex_register);
            if ($db->num_rows($sql_account_ex_register_id) != 0)
                $error_reg .= "<br>" . $reg_msg[4];
        }
    }
    //****************************************
    //must do a email syntax verification
    //****************************************
    //end of verifications
    if ($error_reg == '')
    { //proceed with registration
        //sql query
        $sql_register = "INSERT INTO `web_accounts` ( `id` , `username` ,`email`, `password` , `ip_reg` , `date-register`, `validation_code`, `accesslevel` ) VALUES (NULL, '" .
            htmlentities($_POST['username']) . "', '" . $_POST['email'] . "','" .
            base64_encode(pack('H*', sha1(utf8_encode($_POST['passwd'])))) . "', '" . $_SERVER['REMOTE_ADDR'] .
            "', NOW( ), '" . md5(htmlentities($_POST['username']) . base64_encode(pack('H*',
            sha1(utf8_encode($_POST['passwd']))))) . "', 0);";
        //here should come all the thing related to activation email sending
        require_once ('functions/mail.intern.php');
        $mailtest = mail_activ(htmlentities($_POST['username']), $_POST['email'], $_POST['passwd'],
            URL . 'index.php?page=verify_user&user=' . htmlentities($_POST['username']) .
            '&code=' . md5(htmlentities($_POST['username']) . base64_encode(pack('H*', sha1
            (utf8_encode($_POST['passwd']))))));
        if ($mailtest)
        {
            $content = $smarty->fetch('successfull_reg.tpl');
            $db->query($sql_register);
        } else
            $content = $smarty->fetch('error_at_reg.tpl');
    } else
    {
        //ask for the info again if something went wrong
        $smarty->assign('REGMSG', $error_reg);
        $content = $smarty->fetch('register.tpl');
        $LOGIN = '';
    }
} else
{
    $content = $smarty->fetch('register.tpl');
    $LOGIN = '';
}
?>
Return current item: l2jweb