作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在使用 JavaScript 函数检查数据的有效性后,我想将 oldPassword、newPassword、newPasswordAgain 值传递给 ChangePassword.php。这是表单和 JavaScript:
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="../style/style.css">
</head>
<body>
<div class="navbar">
<ul>
<li><a href="../Pages/Main.php">Home</a></li>
<li><a href="../Pages/Rules.php">Rules</a></li>
<li><a href="../Pages/Builds.php">Builds</a></li>
<li><a href="../Pages/Events.php">Events</a></li>
<li><a href="../Pages/Calendar.php">Calendar</a></li>
<li style="float:right"><a class="active" href="../Pages/UserSettings.php"><?php echo $_SESSION["username"]; ?></a></li>
</ul>
</div>
<div class="changepasswd_bg">
<div class="absolute">
<form name="changePasswordForm" method=POST action="../Pages/ChangePassword.php" onsubmit="return validateForm()">
<input type="password" name="oldPassword" placeholder="Old password" size="100"><br>
<input type="password" name="newPassword" placeholder="New password" size="100"><br>
<input type="password" name="newPasswordAgain" placeholder="New password again" size="100"><br>
<input type="submit" value="Change" size="70">
</form>
<h2 id="output"></h2><br>
<h2 id="debug"></h2>
</div>
</div>
<script>
function validateForm() {
var oldX = document.forms["changePasswordForm"]["oldPassword"].value;
var newX = document.forms["changePasswordForm"]["newPassword"].value;
var newXAgain = document.forms["changePasswordForm"]["newPasswordAgain"].value;
//ki kell tölteni a mezőket
if (oldX === null || oldX === "" || newX === null || newX === "" || newXAgain === null || newXAgain === "") {
document.getElementById("output").innerHTML = "All field need to fill";
document.getElementById("debug").innerHTML = masterPass;
return false;
} // a régi passwordnek a megadottal egyezni kell
else if ('<?php echo $_SESSION["password"] ?>'.toString() !== oldX.toString()) {
document.getElementById("output").innerHTML = "The original passwords are not matches";
return false;
} else if (newX !== newXAgain) {
document.getElementById("output").innerHTML = "The new passwords are not matches";
return false;
} else {
document.getElementById("output").innerHTML = "OK";
return true;
}
}
</script>
</body>
</html>
这是 ChangePassword.php:
<?php
session_start();
?>
<!DOCTYPE html>
<?php
include '../Database/Connect.php';
$oldPassword = $_GET["oldPassword"];
$newPassword = $_GET["newPassword"];
$newPasswordAgain = $_GET["newPasswordAgain"];
if (strlen($oldPassword) == 0 || strlen($newPassword) == 0 || strlen($newPasswordAgain) == 0) {
echo "valamelyik 0 hosszu";
echo $_SESSION["password"] . " " . $oldPassword . " " . $newPassword . " " . $newPasswordAgain;
//header("Location: ../Pages/SomethingWrong.php");
} else if ($_SESSION["password"] !== $oldPassword) {
echo "a session és az ild password nem egyezik";
echo $_SESSION["password"] . " " . $oldPassword . " " . $newPassword . " " . $newPasswordAgain;
// header("Location: ../Pages/SomethingWrong.php");
} else if ($newPassword !== $newPasswordAgain) {
echo "a két password nem egyezik";
echo $_SESSION["password"] . " " . $oldPassword . " " . $newPassword . " " . $newPasswordAgain;
// header("Location: ../Pages/SomethingWrong.php");
} else {
echo "minden ok " . $_SESSION["password"] . " " . $oldPassword . " " . $newPassword . " " . $newPasswordAgain;
}
?>
结果是这些错误:(我也无法在标题上看到变量值。例如:http://ChangePassword.php?name=value ...等)
Notice: Undefined index: oldPassword in D:\apache\htdocs\Pages\ChangePassword.php on line 10
Notice: Undefined index: newPassword in D:\apache\htdocs\Pages\ChangePassword.php on line 11
Notice: Undefined index: newPasswordAgain in D:\apache\htdocs\Pages\ChangePassword.php on line 12
valamelyik 0 hosszuEzredes123
最佳答案
您需要针对您的场景使用 $_POST
$oldPassword = $_POST["oldPassword"];
$newPassword = $_POST["newPassword"];
$newPasswordAgain = $_POST["newPasswordAgain"];
<小时/>
传递敏感信息:
通过 Internet 传递敏感信息时,使用 SSL 套接字更安全。
有关这方面的更多信息,请参阅 Stack 上的以下内容:
关于javascript - 如何将表单值传递给 ChangePassword.php?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38184308/
我是一名优秀的程序员,十分优秀!