Файл: reg.php
Строк: 30
<?
require_once('core/index.php');
require_once('core/func.php');
$title='Регистрация';
require_once('design/head.php');
if($config['access']==1){
echo '<div class="h2">На данный момент регистрация закрыта.</div>';
require_once('design/foot.php');
exit();
}
if($config['access']==1){$err='Регистрация закрыта';}
if($config['ip']==1){
$count=$db->query("SELECT id FROM `users` WHERE `ip`='".$_SERVER['REMOTE_ADDR']."'")->rowCount();
if($count>0){$err='Ошибка. Игрок с данным IP адресом уже зарегистрирован в игре.';}}
if(!isset($err))
{
$ref=isset($_GET['ref'])?num($_GET['ref']):0;
$stmt = $db->prepare("INSERT INTO `users` (`ref`, `time_reg`, `ip`) VALUES (?, ?, ?)");
$stmt -> execute(array($ref, time(), $_SERVER['REMOTE_ADDR']));
$insertId=$db->lastInsertId();
$login='Странник'.$insertId.'';
$hash=md5(md5($insertId.$login.mt_rand(11111,999999)));
request("UPDATE `users` SET `login`=?, `hash`=? WHERE `id`=?", array($login, $hash, $insertId));
setcookie('id_user', $insertId, time() + 86400*7, '/');
setcookie('hash', $hash, time() + 86400*7, '/');
if(isset($ref) && $ref!=0){
request("UPDATE `users` SET `gold`=`gold`+? WHERE `id`=?", array($config['gold_ref'], $ref));
}
header('Location:/');
}else{
$_SESSION['msg']=$err;
header('Location:/');
}
?>