-
Notifications
You must be signed in to change notification settings - Fork 0
/
forgot.php
57 lines (53 loc) · 1.58 KB
/
forgot.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
session_start();
require_once("functions.php");
require_once("db-const.php");
if (logged_in() == true) {
redirect_to("profile.php");
}
?>
<html>
<head>
<title>Forgot your Username or Password? - PHP MySQL Login System | W3Epic.com</title>
</head>
<body>
<h1>Forgot your Username or Password? - PHP MySQL Login System</h1>
<h2>By Arpan Das</h2>
<hr />
<p>Please enter your email address below.</p>
<form action="forgot.php" method="post">
Email: <input type="text" name="email" />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if (isset($_POST['submit'])) {
## connect mysql server
$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
# check connection
if ($mysqli->connect_errno) {
echo "<p>MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}</p>";
exit();
}
## query database
# fetch data from mysql database
$sql = "SELECT email FROM users WHERE email LIKE '{$_POST['email']}' LIMIT 1";
if ($result = $mysqli->query($sql)) {
$user = $result->fetch_array();
} else {
echo "<p>MySQL error no {$mysqli->errno} : {$mysqli->error}</p>";
exit();
}
if ($result->num_rows == 1) {
// email login cresendials to the user's email
// use phpMailer tutorial on w3epic
echo "<p>Login credentials has been sent to <b>{$_POST['email']}</b></p>";
} else {
echo "<p>Sorry, no user found with this email.</p>";
}
}
?>
<a href="login.php">Login</a> | <a href="register.php">Register</a>
<hr />
<h1><a href="http://w3epic.com/">W3Epic.com</a></h1>
</body>
</html>