PHP 코드 :JS와 PHP 사이의 연결을 확인하는 방법
$dom = new DOMDocument;
$headtitle = "Register";
$errors = array();
if(isset($_POST['register'])){
$username = preg_replace('/[^A-Za-z]/', '', $_POST['username']);
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$password = $_POST['password'];
$c_password = $_POST['c_password'];
$birthday = $_POST['birthday'];
$country = $_POST['country'];
$gender = $_POST['gender'];
$age = $_POST['age'];
$level = $_POST['level'];
$date = $_POST['date'];
if(file_exists('users/' . $username . '.xml')){
$errors[] = ' Username already exists';
}
if($username == ''){
$errors[] = ' Username is missing. Try again.';
}
if($name == ''){
$errors[] = ' Name is missing. Try again.';
}
if($lastname == ''){
$errors[] = ' Lastname is missing. Try again.';
}
if($country == ''){
$errors[] = ' Country is missing. Try again.';
}
if($gender == ''){
$errors[] = ' Gender is missing. Try again.';
}
if($age == ''){
$errors[] = ' Age is missing. Try again.';
}
if($email == ''){
$errors[] = ' Email is missing. Try again.';
}
if($password == '' || $c_password == ''){
$errors[] = ' Passwords are missing. Try again.';
}
if($password != $c_password){
$errors[] = ' Passwords do not match';
}
if(count($errors) == 0){
$xml = new SimpleXMLElement('<user></user>');
$xml->addChild('name', ($name));
$xml->addChild('lastname', ($lastname));
$xml->addChild('password', md5($password));
$xml->addChild('birthday', $birthday);
$xml->addChild('country', $country);
$xml->addChild('gender', $gender);
$xml->addChild('age', $age);
$xml->addChild('email', $email);
$xml->addChild('level', $level);
$xml->addChild('date', $date);
$xml->asXML('users/' . $username . '.xml');
header('Location: index.php');
die;
}
}
자바 스크립트 코드 :
이제function vaildate() {
if (document.getElementById('username').value.length <= 4) {
document.getElementById('errors').innerHTML = "Username must me more than 4 words <br />";
return false;
}
return true;
}
내 문제, 내가 클릭하면 (즉 name="login"
및 onclick="vaildate();"
을 포함) 버튼을 제출하는 것이 그는 단지 php 오류를 excute하고 javascript 오류를 무시합니다 (id="username"
은 4 단어 미만 임).
제 질문은 자바를 어떻게 만들 수 있습니까? & PHP 오류가 작동합니까? PHP뿐만 아니라 시스템은 자바 스크립트를 무시합니다.
는 여러분 모두 감사합니다 .. 편집:
이 또한 내가if(count($errors) > 0){
echo '<font color="red"><ul>';
foreach($errors as $e){
echo '<li>' . $e . '</li>';
}
echo '</ul></font>';
}
아무도 예를 들어 사용자 이름을 선택하지 않았 으면합니다. ../../ – thatidiotguy
당신은 당신의 희망에 정말로 도움이되지 않습니다. – copypaste
나는 당신의 코드가 기본 주입 공격에 매우 취약한 결함이 있음을 지적하고자합니다. 귀하의 실제 질문에 관해서는 응답을 쓰고있었습니다 – thatidiotguy