2013-02-28 5 views
0

기본 로그인 및 등록 페이지를 만들고 비밀번호 변경 양식이 완료되면 changepassword.php? success로 리디렉션하고 싶습니다. 리디렉션 된 페이지는 브라우저에 입력하면 제대로 작동하지만 양식을 제출할 때? 성공 대신 changepassword.php 페이지가 다시로드되고 PHP 코드 블록의 모든 항목이 표시되지 않습니다 (즉, 양식, 열 오른쪽 및 바닥 글).헤더 위치가 작동하지 않습니다.

<!DOCTYPE html> 
<html> 
<?php 
include ("storescripts/init.php"); 
protect_page(); 
include ("includes/overall/head.php"); 

if (empty($_POST) === false){ 
$required_fields = array('current_password','password','password_again'); 
foreach ($_POST as $key=>$value) { 
    if (empty($value) && in_array($key, $required_fields) == true) { 
     $errors[] = 'Fields marked with an asterisk are required'; 
     break 1; 
    } 
} 
if ($_POST['current_password'] === $member_data['mem_password']) { 
    if(trim($_POST['password']) !== trim($_POST['password_again'])){ 
     $errors[] = 'Your new passwords do not match'; 
    } else if (strlen($_POST['password']) <6) { 
     $errors[] = 'Your password must be at least 6 characters'; 
    } 
} else { 
    $errors[] = 'Your current password is incorrect'; 
} 
} 
?> 
<body> 
<?php include ("includes/overall/template_header.php");?> 
<div id="mainDivShort"> 
    <h1>Change Password</h1> 
    <div id="divBreak"></div> 
    <?php include ("includes/overall/column_left.php"); ?> 
    <div id="middleContent"> 
     <?php 
     if (isset($_GET['success']) && empty($_GET['success'])) { 
echo 'You have been registered successfully'; 
} else { 

    if (empty($_POST) === false && empty($errors) === true) { 
     //echo "**********************"; 
     change_password($session_mem_id, $_POST['password']); 
     header('Location: changepassword.php?success'); 
     exit(); 
    } else if (empty($errors) === false) { 
     echo output_errors($errors); 
    } 

    ?> 
     <form action="" method="post"> 
      <ul> 
       <li>Current Password*: <br> <input type="password" 
        name="current_password"> 
       </li> 
       <li>New Password*: <br> <input type="password" name="password"> 
       </li> 
       <li>Repeat New Password*: <br> <input type="password" 
        name="password_again"> 
       </li> 
       <li><input type="submit" value="Change"> 
       </li> 
      </ul> 
     </form> 
     <?php }?> 
    </div> 
    <?php include ("includes/overall/column_right.php"); ?> 
</div> 
<?php include ("includes/overall/template_footer.php");?> 
</body> 
</html> 

그리고 당신이 암호 변경 기능을 볼 필요 넣다 :

function change_password($mem_id, $password) { 
$mem_id = (int)$mem_id; 

mysql_query("UPDATE `members` SET `mem_password` = '$password' WHERE `mem_id` = $mem_id"); 
} 

암호는 데이터베이스에 잘 업데이트, 그냥 순수하게 리디렉션하지 않습니다 아래 내 changepassword.php 코드 성공 페이지로 미리 감사드립니다.

+0

"echo"또는 "print"를 전에 만들지 않았 으면 헤더가 작동하기 때문에 'header'앞에 아무 것도 출력하지 마십시오. – jcho360

+0

헤더가 출력 전에 나오고 html 앞에 와야합니다. – Jrod

+0

그 전에 어떤 html도 출력한다면'header'을 사용하는 것은 의미가 없습니다. –

답변

-1

콘텐츠를 출력 한 후에 header('Location: changepassword.php?success');을 입력 할 수 없습니다. 또한 header 리디렉션에는 절대 경로가 포함되어야합니다.

+2

downvoter가 아니라 절대 경로를 사용하지 않아도됩니다. –

+0

@ Mr.Alien HTTP/1.1은»Location : – MarcinWolny

0

헤더 지시어는 내용, 내용, 줄 바꿈, 공백, html 등을 포함해야합니다. 그렇지 않으면 헤더를 보내는 것이 너무 늦습니다. 1 비트의 콘텐츠가 전송 되 자마자 헤더가 이미 사라졌습니다.

+0

의 인수로 절대 URI를 요구합니다. 'echo'당신은 성공적으로 등록되었습니다 ';' 아래의 if 문에 대한 조건이 충족되는 경우에만 true가됩니다. 그럼 어떻게 다른 사람을 배치 할 수 있겠습니까? – jhetheringt7

관련 문제