我正在处理resetcore 中的密码php。我送code的变量reset.php,以resetPassword.php这样的页面:reset.php$code = uniqid(true);$url = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF'])."/resetPassword.php?code=$code"resetPassword.phpglobal $code;if(!isset($_GET['code'])){ echo "There is No Code there !!!";}if(isset($_GET['code'])){ $code = $_GET['code']; echo "The code is set at first , just at visit of the page ".$code;}// make sure there is row in the table that matches that passed code $findEmail = mysqli_query($link,"SELECT `email` from resetpasswords WHERE `code` = '$code' ");if(mysqli_num_rows($findEmail)==0){ // if no row found echo "<h2 class = 'text text-center'>No Record regarding this email !</h2>"; exit();} // when form submits if(isset($_POST['reset'])){ $password = md5($_POST['password']); $confirm = md5($_POST['confirm']); if($password!=$confirm){ echo "Password Don't matches !"; exit(); } $row = mysqli_fetch_array($findEmail); $email = $_POST['email']; $updatePass = mysqli_query($link,"UPDATE `user` SET user_password = '$confirm' where email = '$email'"); if($updatePass){ $query = mysqli_query($link,"DELETE FROM resetpasswords where code = '$code' "); exit('Password Updated, Please Login with the New Password'); } else{ exit('Something went wrong'); }}问题:问题是当我提交表单时,它一直到页面顶部,并resetPassword.php从顶部开始执行页面,因此对于resetPassowrd.php页面,它不能使用get该$code变量。因为当我提交表单时,(!isset($_GET['code']))顶部的条件resetPassword.php变为真,它给了我: There is No Code there !!!$code当我提交表单时,我想拥有它。我试过的:我尝试使用hidden值为 of 的字段,$code但这没有用。请帮帮我谢谢
2 回答

慕婉清6462132
TA贡献1804条经验 获得超2个赞
考虑以下几点
1) 使用准备好的语句和参数化查询。
2) 使用password_hash()
和password_verify()
保护您的密码。
3) 在resetPassword.php
页面中,如果你用action="resetPassword.php"
这个提交表单将重定向到resetPassword.php。所以用这个替换你的动作
$full_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://{$_SERVER['HTTP_HOST']}{$_SERVER['REQUEST_URI']}"; <form action="<?php echo $full_url ?>" method="POST">

MMTTMM
TA贡献1869条经验 获得超4个赞
您在隐藏字段中缺少 name 属性,因此您无法找到 $code 的值。
代替
<input type="hidden" value="<?php echo $code;?>">
尝试
<input type="hidden" value="<?php echo $code;?>" name="code" />
- 2 回答
- 0 关注
- 247 浏览
添加回答
举报
0/150
提交
取消