- 정보공유
[그누보드팁] 회원아이디 자동 생성 함수
function generateUniqueUserId() {
global $g5;
// 사용할 문자셋 (영문 소문자 + 숫자 + 특수문자)
$chars = 'abcdefghijklmnopqrstuvwxyz0123456789';
$length = 10;
do {
// 랜덤 아이디 생성
$userId = '';
for ($i = 0; $i < $length; $i++) {
$userId .= $chars[random_int(0, strlen($chars) - 1)];
}
// DB 중복 체크
$query = sprintf("SELECT COUNT(*) as cnt FROM {$g5['member_table']} WHERE mb_id = '%s'", $userId);
$mb = sql_fetch($query);
$count = (int)$mb['cnt'];
} while ($count > 0); // 중복이면 다시 생성
return $userId;
}