기본 로그인 및 등록 페이지를 만들고 비밀번호 변경 양식이 완료되면 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 코드 성공 페이지로 미리 감사드립니다.
"echo"또는 "print"를 전에 만들지 않았 으면 헤더가 작동하기 때문에 'header'앞에 아무 것도 출력하지 마십시오. – jcho360
헤더가 출력 전에 나오고 html 앞에 와야합니다. – Jrod
그 전에 어떤 html도 출력한다면'header'을 사용하는 것은 의미가 없습니다. –