Mình có code đăng ký
PHP
<?php $title = 'Đăng Ký'; include 'head.php'; if (!isset($_SESSION['login'])){ include 'func.php'; $chacode = rand_string(5); if (!isset($_POST['code'])){ $_SESSION['captcha'] = $chacode; } if (isset($_POST['registration'])){ $account = htmlspecialchars($_POST['account']); $account1 = str_replace($account1," ",""); $password = htmlspecialchars($_POST['password']); $repassword = htmlspecialchars($_POST['repassword']); $email = htmlspecialchars(strtolower($_POST['email'])); $accd = rand(00000,99999); $captcha = htmlspecialchars($_POST['code']); if ($account == NULL){ $eracc = 'Bạn chưa nhập tên tài khoản !'; $xulya = '0'; } if ($password == NULL){ $erpass = 'Bạn chưa nhập mật khẩu !'; $xulya = '0'; } if ($repassword == NULL){ $errepass = 'Bạn chưa nhập lại mật khẩu !'; $xulya = '0'; } if ($email == NULL){ $eremail = 'Bạn chưa nhập email !'; $xulya = '0'; } if ($captcha == NULL){ $ercap = 'Bạn chưa nhập mã xác nhận !'; $xulya = '0'; } if ($xulya != '0'){ if(!preg_match('#[a-zA-Z0-9-.]#is',$account,$dcm)){ $eracc = 'Chỉ cho phép đăng ký tài khoản có ký tự a-z,A-Z,0-9,-. !'; $xuly = '0'; } if(!preg_match('#[a-zA-Z0-9-.]#is',$password,$dcm)){ $erpass = 'Chỉ cho phép đăng ký mật khẩu có ký tự a-z,A-Z,0-9,-. !'; $xuly = '0'; } if(!preg_match('#[a-zA-Z0-9-.]@gmail.com#is',$email,$dcm)){ $eremail = 'Chỉ cho phép đăng ký thư điện tử có ký tự a-z,A-Z,0-9,-. và @gmail.com !'; $xuly = '0'; } } if ($xuly != '0'){ if (strlen($account) > '15'){ $eracc = 'Tên tài khoản giới hạn 15 ký tự !'; $xuly1 = '0'; } if (strlen($password) > '20'){ $erpass = 'Mật khẩu giới hạn 20 ký tự !'; $xuly1 = '0'; } if (strlen($email) > '30'){ $eremail = 'Thư điện tử giới hạn 30 ký tự !'; $xuly1 = '0'; } if ($xuly1 != '0'){ if (strlen($account) < '4'){ $eracc = 'Tên tài khoản ít nhất 4 ký tự !'; $xuly11 = '0'; } if (strlen($password) < '6'){ $erpass = 'Mật khẩu ít nhất 6 ký tự !'; $xuly11 = '0'; } if (strlen($email) < '8'){ $eremail = 'Thư điện tử ít nhất 8 ký tự !'; $xuly11 = '0'; } } if ($xuly11 != '0'){ $sql = mysql_query('SELECT account FROM user WHERE account = "'.$account.'"'); if (mysql_num_rows($sql) > '0'){ $eracc= 'Tài khoản đã tồn tại !'; $insert = '0'; } if ($repassword != $password){ $errepass = 'Mật khẩu nhập lại không đúng !'; $insert = '0'; } $sqll = mysql_query('SELECT email FROM user WHERE email = "'.$email.'"'); if (mysql_num_rows($sqll) > '0'){ $eremail= 'Email đã tồn tại !'; $insert = '0'; } if (isset($_POST['code'])){ if ($captcha == $_SESSION['captcha']){ echo ''; $_SESSION['captcha'] = $chacode; } else { $ercap = 'Mã xác nhận không đúng !'; $_SESSION['captcha'] = $chacode; $insert = '0'; } } if ($insert != '0'){ $timereg = date('H:i:s d/m/Y'); mysql_query('INSERT INTO user SET account = "'.$account.'",password = "'.md5($password).'",email = "'.$email.'",accd = "'.$accd.'",timereg = "'.$timereg.'"'); echo '<div class="list3">Đăng ký thành công ! Mã bảo mật của bạn là '.$accd.'</div>'; } } } } if ($eracc == '' && $_POST['registration'] == ''){ $eracc = '(Tên tài khoản ít nhất là 4 ký tự ,nhiều nhất là 15 ký tự)'; } if ($erpass == '' && $_POST['registration'] == ''){ $erpass = '(Mật khẩu ít nhất là 6 ký tự ,nhiều nhất là 20 ký tự)'; } if ($errepass == '' && $_POST['registration'] == ''){ $errepass = '(Nhập lại mật khẩu đã nhập khung trên)'; } if ($eremail == '' && $_POST['registration'] == ''){ $eremail = '(Thư điện tử dùng để lấy lại mật khẩu ,ký tự nhiều nhất 30 ký tự)'; } echo '<div class="list"><form action ="" method="post">Tên tài khoản: '.$eracc.'<br><input type="text" name="account" value=""><br>Mật khẩu: '.$erpass.'<br><input type="password" name="password" value=""><br>Nhập lại mật khẩu: '.$errepass.'<br><input type="password" name="repassword" value=""><br>Thư điện tử: '.$eremail.'<br><input type="text" name="email" value=""><br>Mã xác nhận ['.$_SESSION['captcha'].']: '.$ercap.'<br><input type="text" name="code" value=""><br><input type="submit" name="registration" value="Đăng Ký"></form></div>'; } else { echo '<div class="phdr">Đăng Ký</div><div class="list2">Chỉ dành cho thành viên chưa đăng nhập !</div>'; } include 'foot.php'; ?>
Mình đã dùng preg match mà sao nhập dấu cách nó k lọc v?
Giúp vs thank
![[OFF]](/assets/images/off.gif)