$smarty->assign('registration_error', $error); $smarty->assign('register_username', $_POST['username']); $smarty->display('index.tpl.html'); exit; } if ($user_count) { $error = "Username '{$_POST['username']}' already exists!\n" . "Please choose a different one!"; $smarty->assign('registration_error', $error); $smarty->assign('register_username', $_POST['username']); $smarty->display('index.tpl.html'); exit; } $current_time = time(); $md5_pass = md5($_POST['password']); $insert_query = "INSERT INTO users (username, password, date_regged, date_access, ip_address) VALUES " . "('{$_POST['username']}', '{$md5_pass}', {$current_time}, {$current_time}, '{$_SERVER['REMOTE_ADDR']}')"; $res = $db->query($insert_query); if ($db->isError()) { $error = "Registration failed! There was a database error: " . $db->getError(); $smarty->assign('registration_error', $error); $smarty->assign('register_username', $_POST['username']); $smarty->display('index.tpl.html'); exit; } $_SESSION['user_id'] = $db->getLastInsertId(); $_SESSION['username'] = $_POST['username']; setcookie('user_id', $_SESSION['user_id'], time() + 3600 * 24 * 10); # expire after 10 days setcookie('md5_pass', $md5_pass, time() + 3600 * 24 * 10); # Display a welcome message to the user as she/he just got registered. $_SESSION['welcome'] = 1; header("Location: {$SITE_URL}");