-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforgot.php
79 lines (73 loc) · 2.17 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
error_reporting(0);
$msg='';
if(isset($_REQUEST['msg']))
$msg=$_REQUEST['msg'];
if(isset($_REQUEST['email'])&&$_REQUEST['email']!='')
{
require_once("connect.php");
$email=$_REQUEST['email'];
$result=mysql_query("SELECT * FROM `users` WHERE `email`='$email'");
$noofrows=mysql_num_rows($result);
if($noofrows!=1)
{
header('Location: forgot.php?msg=No such email exists, check your email address once again.');
exit;
}
$row=mysql_fetch_array($result);
/*send email*/
$acturl="http://localhost/xampp/snapheap/reset.php?email=".$row['email']."&code=".strrev($row['salt']);
$to=base64_encode($row['email']);
$toname=base64_encode($row['name']);
$subject=base64_encode("SnapHeap | Your password reset link");
$body=base64_encode("<h3><i>Welcome to Snapheap</i></h3><br/>Here is the password reset link to your account on snapheap.<br/><a href=\"".$acturl."\">".$acturl."</a><hr/>© SnapHeap 2012");
$url="http://localhost/xampp/phpmailer/examples/snapheapmailer.php";
$fields = array(
'to' => urlencode($to),
'toname' => urlencode($toname),
'subject' => urlencode($subject),
'body' => urlencode($body)
);
//url-ify the data for the POST
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
//execute post
$result = curl_exec($ch);
//echo $result;
//close connection
curl_close($ch);
/*end of sending email*/
header('Location: forgot.php?msg=Password reset mail been sent, check your email for the same.');
}
?>
<html>
<head>
<title>SnapHeap</title>
</head>
<body>
<div>
<table width="100%">
<tr>
<td>
<a href="index.php"><h3><i>SnapHeap</i></h3></a>
</td>
<td align="right">
<a href="login.php">Login</a> | <a href="register.php">Signup</a>
</td>
</tr>
</table>
</div>
<hr/>
<?php echo $msg.'<br/>'; ?>
<h3><i>Forgot password</i></h3>
<form action="" method="post">
Email address:<input type="text" id="email" name="email" /><br/>
<input type="submit" value="Reset password" />
</form>
</body>
</html>