<?php
require_once('system/func.php');
$title = 'Регистрация';
require_once('system/header.php');

noauth(); // Закроем от не авторизованных

if (isset($_POST['captcha'])) {

    if ($_POST['captcha'] != $_SESSION['captcha']) {
        $_SESSION['msg'] = 'Неверный проверочный код';
        header('location: /r.php?');
        exit();
    }

    $r = rand(100, 1000000);

    $name = "Игрок$r";
    $pass = rand(10000, 44454545);


    //if (mysql_num_rows(mysql_query('SELECT * FROM `users` WHERE `ip` = "' . $_SERVER['REMOTE_ADDR'] . '"')) != 0) {
       // $_SESSION['msg'] = 'У вас уже есть аккаунт.';
       // header('location: /');
       // exit;
   // }

    if (mysql_query("INSERT INTO `users` SET `login` = '" . $name . "', `password` = '" . md5($pass) . "', `sex` = '" . 1 . "', `side` = 'good', `duel_fight` = '20' ,`save` = '1', `almaz` = '100', `registr` = '" . time() . "' ")) {

        if (isset($_SESSION['ref'])) {
            $id = mysql_insert_id();
            mysql_query("update `users` set `id_partner` = '" . intval($_SESSION['ref']) . "' where (`id` = '" . $id . "')");
        }


        setcookie('login', $name, time() + 86400 * 365, '/');
        setcookie('password', md5($pass), time() + 86400 * 365, '/');
        header('location: /');
        exit();
    }

}
?>
<div class="block_C">Начало игры</div>
<form class="cont_ent" action="" method="post">
    <div class="header">
        Проверочный код <img src="/captcha/captcha.php" id="captcha"
                             onclick="document.getElementById('captcha').src ='/captcha/captcha.php?' + Math.random()"><br>
        <input class="form_text" type="text" name="captcha" maxlength="25" placeholder="" autocomplete="off"
               required/><br/>
        <input type="submit" class="auth_login" name="pass" class="btn_grey" value="Начать игру">
</form>
</div>
<?php
echo div('bbtn mb5') . ' <a href="/"> Вернуться назад </a> </div>';
require_once('system/footer.php');
