2013-06-19 1 views
0

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>'; 
} 
+1

아무도 예를 들어 사용자 이름을 선택하지 않았 으면합니다. ../../ – thatidiotguy

+0

당신은 당신의 희망에 정말로 도움이되지 않습니다. – copypaste

+1

나는 당신의 코드가 기본 주입 공격에 매우 취약한 결함이 있음을 지적하고자합니다. 귀하의 실제 질문에 관해서는 응답을 쓰고있었습니다 – thatidiotguy

답변

1

이 시도 :

onclick="return vaildate();" 

당신은 그냥 전화하지, 유효성 검사 기능을 반환합니다 (true 또는 false를 반환) 할 필요가있다.

+0

고마워요! 나는 받아들이는 것을 잊지 않을 것이다. :) – copypaste

0

자바 스크립트와 PHP 당신이 보여주고 외모 미세 PHP 오류를 반향이 코드를 얻었다. 우리가 가지고 있지 않은 것은 로그인 페이지의 실제 마크 업입니다. 제 마크 업이 자바 스크립트에있는 코드와 일치하지 않는다고 의심됩니다.

당신은 또한 시도하고 더 구체적으로 당신이

내 질문에 내가 할 수있는 방법 자바 스크립트 & PHP 오류가 작동되고 무슨 뜻인지 설명 할 수 있다면? PHP뿐만 아니라 시스템은 자바 스크립트를 무시합니다.

Javascript 디버거를 사용하여 자바 스크립트 (페이지의 다른 부분)에 오류가 있는지 확인하셨습니까?

+0

코드는 실제로 문제가 아닙니다. 내가 원하는 건 자바 스크립트가 코드를 제출하지 않고 (오류 발생시) 중단하고 새 사용자를 만드는 것입니다. – copypaste

관련 문제