<html><head><title>User activation page</title>
</head>
<body>
<?php
/* phpemailuser by georgfly */
include("config.inc.php");
if(empty($_GET['ak']) || empty($_GET['ud']))
{
$errormsg = "We have sent you an email containing a link to activate your accout.<br>Please check your email.<br>
<a href=\"$dirurl/login_reg.php\">Click here to get back to login.</a>";
}
if (empty($errormsg))
{
$ak = strip_tags(trim($_GET['ak']));
$ud = strip_tags(trim($_GET['ud']));
$cxn = mysqli_connect($mysqlhost,$mysqluser,$mysqlpass,$mysqldb)
or die("Couldn't connect to server");
$ak = mysqli_real_escape_string($cxn,$ak);
$ud = mysqli_real_escape_string($cxn,$ud);
$doundo = false;
if (!empty($_GET['action'])){
$akprev = strip_tags(trim($_GET['action']));
if ($akprev == "undo") $doundo = true;
}
if ($doundo){
$sql = "SELECT * FROM user WHERE actkeyprev = '$ak' AND uid = $ud";
} else {
$sql = "SELECT * FROM user WHERE actkey = '$ak' AND uid = $ud";
}
$result = mysqli_query($cxn,$sql)
or die("Query died.");
$row = mysqli_fetch_assoc($result);
$num = mysqli_num_rows($result);
if($num != 0){
//confirm the email and update the users database
if ($row['activated'] == 0) // if not already activated
{
// check if activation key is expired
$actkey_date = strtotime($row['actkey_date']); // timestamp in seconds
$timediff = (time()-$actkey_date)/(60*60);
if ($timediff > $activationkeyexpire){
echo "Sorry, this activation key for ".$row['user_email']." is already expired.<br>";
echo "You can request a new activation key at the <a href=\"$dirurl/login_reg.php\">login page</a>.";
exit;
} else {
// everything seems ok, so lets activate!
$today = date("Y-m-d H:i:s");
if ($doundo){
$sql = "UPDATE user SET user_email='".$row['prevemail']."', actkeyprev=null, prevemail='".$row['user_email']."', activated=1, actkey_date='$today' WHERE actkeyprev = '$ak' AND uid = $ud";
$update = mysqli_query($cxn,$sql)
or die ("Activation query died.");
echo "Account has been re-activated for ".$row['prevemail'].".<br>";
echo "<a href=\"$dirurl/login_reg.php\">Please click here to log in.</a>";
exit;
} else {
$sql = "UPDATE user SET activated = 1, actkeyprev=null, actkey_date = '$today' WHERE actkey = '$ak' AND uid = $ud";
$update = mysqli_query($cxn,$sql)
or die ("Activation query died.");
echo "Congratulations! Account for ".$row['user_email']." is active!<br>";
echo "<a href=\"$dirurl/login_reg.php\">Please click here to log in.</a>";
exit;
}
}
} else {
echo "Account for ".$row['user_email']." is already active.<br>";
echo "<a href=\"$dirurl/login_reg.php\">Please click here to log in.</a>";
exit;
}
} else
{
$errormsg = 'User could not be activated with the information provided.<br>';
$errormsg .= "Please double check the link in your email or try again to <a href=\"$dirurl/login_reg.php\">login here</a>.";
}
}
echo $errormsg;
?>
</body></html>