forgot_password.php

来自「用PHP/MySQL/Apache实现的简单用户注册/登录系统。」· PHP 代码 · 共 56 行

PHP
56
字号
<?php
	require_once('includes/config.inc.php');
	$page_title='Fogot Your Password';
	include('includes/header.html');
	
	if(isset($_POST['submitted'])){
		require_once(MYSQL);
		$uid=false;
		if(!empty($_POST['email'])){
			$q='SELECT user_id FROM users WHERE email="'.mysqli_real_escape_string($dbc,$_POST['email']).'"';
			$r=mysqli_query($dbc,$q) or trigger_error("Query: $q\n<br/>Mysql Error: ".mysqli_error($dbc));
			if(mysqli_num_rows($r)==1){
				list($uid)=mysqli_fetch_array($r,MYSQL_NUM);
			}else{
				echo'<p class="error">The submitted email address does not match those on file.</p>';
			}
		}else{
			echo '<p class="error">You fogot to enter your email address.</p>';
		}
		if($uid){
			$p=substr(md5(uniqid(rand(),true)),3,10);
			
			$q="UPDATE users SET pass=SHA1('$p') WHERE user_id=$uid LIMIT 1";
			$r=mysqli_query($dbc,$q) or trigger_error("Query: $q\n<br/>Mysql Error: ".mysqli_error($dbc));
			if(mysqli_affected_rows($dbc)==1){
				$body="Your password to log into MySite has been temporarily changed to '$p'. Please log in using this password and this email address. Then you may change your password to something more farmiliar.";
				mail($_POST['email'],'Your temporary password.',$body,'From: admin@mysite.com');
				
				echo'<h3>Your password has been chaned. You will receive the new, temporary password at the email address with whiche you registered. Once you have logged in with this password, you may change it by click on the "Change Password" link.</h3>';
				mysqli_close($dbc);
				include('includes/footer.html');
				exit();
			}else{
				echo '<p class="error"> Your password could not been changed due to a system error. We apologize for any inconvenience.</p>';
				
			}
		}else{
			echo'<p class="error">Please try again.</p>';
		}
		mysqli_close($dbc);
	}
?>
<h1>Reset Your Password</h1>
<p>Enter your email address below and your password will be reset.</p>
<form action="forgot_password.php" method="post">
<fieldset>
	<p><b>Eamil Address: </b><input type="text" name="email" size="20" maxlength="40" value="<?php if(isset($_POST['email']) )echo $_POST['email']; ?>"/></p>
</fieldset>

<div align="center"><input type="submit" name="submit" value="Reset My Password"/></div>
<input type="hidden" name="submitted" value="TRUE"/>
</form>

<?php
	include('includes/footer.html');
?>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?