31 lines
1.3 KiB
PHP
Executable file
31 lines
1.3 KiB
PHP
Executable file
<?php
|
|
// Change this to your connection info.
|
|
include('../config.php');
|
|
// Try and connect using the info above.
|
|
$con = mysqli_connect($servername, $username, $password, $dbname);
|
|
if (mysqli_connect_errno()) {
|
|
// If there is an error with the connection, stop the script and display the error.
|
|
exit('Failed to connect to MySQL: ' . mysqli_connect_error());
|
|
}
|
|
// First we check if the email and code exists...
|
|
if (isset($_GET['email'], $_GET['code'])) {
|
|
if ($stmt = $con->prepare('SELECT * FROM accounts WHERE email = ? AND activation_code = ?')) {
|
|
$stmt->bind_param('ss', $_GET['email'], $_GET['code']);
|
|
$stmt->execute();
|
|
// Store the result so we can check if the account exists in the database.
|
|
$stmt->store_result();
|
|
if ($stmt->num_rows > 0) {
|
|
// Account exists with the requested email and code.
|
|
if ($stmt = $con->prepare('UPDATE accounts SET activation_code = ? WHERE email = ? AND activation_code = ?')) {
|
|
// Set the new activation code to 'activated', this is how we can check if the user has activated their account.
|
|
$newcode = 'activated';
|
|
$stmt->bind_param('sss', $newcode, $_GET['email'], $_GET['code']);
|
|
$stmt->execute();
|
|
echo 'Your account is now activated! You can now <a href="index.php">login</a>!';
|
|
}
|
|
} else {
|
|
echo 'The account is already activated or doesn\'t exist!';
|
|
}
|
|
}
|
|
}
|
|
?>
|