-
Notifications
You must be signed in to change notification settings - Fork 0
/
activatenewemail.php
71 lines (66 loc) · 2.56 KB
/
activatenewemail.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
<?php
//The user is re-directed to this file after clicking the link received by email and aiming at proving they own the new email address
//link contains three GET parameters: email, new email and activation key
session_start();
include('connection.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>New Email activation</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<style>
h1{
color:purple;
}
.contactForm{
border:1px solid #7c73f6;
margin-top: 50px;
border-radius: 15px;
}
</style>
</head>
<body>
<div class="container-fluid">
<div class="row">
<div class="col-sm-offset-1 col-sm-10 contactForm">
<h1>Email Activation</h1>
<?php
//If email, new email or activation key is missing show an error
if(!isset($_GET['email']) || !isset($_GET['newemail']) || !isset($_GET['key'])){
echo '<div class="alert alert-danger">There was an error. Please click on the link you received by email.</div>'; exit;
}
//else
//Store them in three variables
$email = $_GET['email'];
$newemail = $_GET['newemail'];
$key = $_GET['key'];
//Prepare variables for the query
$email = mysqli_real_escape_string($link, $email);
$newemail = mysqli_real_escape_string($link, $newemail);
$key = mysqli_real_escape_string($link, $key);
//Run query: update email
$sql = "UPDATE users SET email='$newemail', activation2='0' WHERE (email='$email' AND activation2='$key') LIMIT 1";
$result = mysqli_query($link, $sql);
//If query is successful, show success message
if(mysqli_affected_rows($link) == 1){
session_destroy();
setcookie("rememeberme", "", time()-3600);
echo '<div class="alert alert-success">Your email has been updated.</div>';
echo '<a href="index.php" type="button" class="btn-lg btn-sucess">Log in<a/>';
}else{
//Show error message
echo '<div class="alert alert-danger">Your email could not be updated. Please try again later.</div>';
echo '<div class="alert alert-danger">' . mysqli_error($link) . '</div>';
}
?>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>