ik ben bezig met een activation email code.
bijna alles werkt.
1 account kan ik activeren.
maar als een ander account aanmaak. kan ik hem niet activeren hij zegt dan dat ie de email niet kan vinden en de activationcode niet kan vinde. maar dat kan hij wel bijn mijn 1e account en mijn 2e account.
waarom niet???
Hopelijk kunnen jullie helpen.
activate.php
<?php
if (isset($_GET['succes']) == true && empty($_GET['succes']) == true) {
echo '<h2>Thanks, we\'ve activated you\'re account...</h2>';
echo '<p>And you\'re free to log in.</p>';
} else if (isset($_GET['email'], $_GET['email_code']) == true) {
$email = trim($_GET['email']);
$email_code = trim($_GET['email_code']);
if (email_exists($email) == false) {
$errors[] = 'Oops, something went wrong, and we couldn\'t find that email!';
} else if (activate($email, $email_code) == false) {
$errors[] = 'We had some problems to activate you\'re account.';
}
if (empty($errors) == false) {
echo '<h2>Oops...</h2>';
echo output_errors($errors);
} else {
header("Location: activate.php?succes");
}
} else {
header("Location: index.php");
exit();
}
?>
user.php
<?php
function activate($email, $email_code) {
$email = mysql_real_escape_string($email);
$email_code = mysql_real_escape_string($email_code);
$query = mysql_result(mysql_query("SELECT user_id FROM users WHERE email = '$email' AND email_code = '$email_code' AND active = 0"), 0);
if ($query == 1) {
mysql_query("UPDATE users SET active = 1 WHERE email = '$email'");
return true;
} else {
return false;
echo $register_data['email'];
}
}
function register_user($register_data){
array_walk($register_data, 'array_sanitize');
$register_data['password'] = md5($register_data['password']);
$fields = implode(', ', array_keys($register_data));
$data = '\'' . implode('\', \'', $register_data) . '\'';
mysql_query("INSERT INTO users ($fields) VALUES ($data)");
mail($register_data['email'], 'M-Tutorial - Activation code!', "Hello " . $register_data['first_name'] . ",\n\nThanks for that you registerd on our website.\n\nTo activate you're account please click the link below.\n\nActivation code: http://localhost/tutorial/activate.php?email=" . $register_data['email'] . "&email_code=" . $register_data['email_code'] . "\n\nWe all thank you and wish you much enjoy to our website. Kind regards from the MTUT Crew.", 'From: [email protected]');
}
function email_exists($email) {
$email = sanitize($email);
$query = mysql_query("SELECT user_id FROM users WHERE email = '$email'");
if (mysql_num_rows($query) == 0) {
} else {
return (mysql_result($query, 0) == 1) ? true : false;
}
}
?>
register.php
<?php
if (isset($_GET['succes']) && empty($_GET['succes'])) {
echo 'You\'ve been registerd succesfully.<br>Please activate you\'re account to log in on our website.';
} else {
if (empty($errors) == false) {
echo output_errors($errors);
} else if (empty($_POST) == false && empty($errors) == true) {
$register_data = array(
'username' => $_POST['username'],
'password' => $_POST['password'],
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email_code' => md5($_POST['username'] + microtime()),
'email' => $_POST['email']
);
register_user($register_data);
header("Location: register.php?succes");
exit();
}
?>
general.php
<?php
function email($to, $subject, $header) {
mail($to, $subject, $body, 'From: [email protected]');
}
?>
Ik geef alleen de stukjes code mee de van belang zijn.!!.
En jaja ik doe het nog met mysql. dat is omdat ze het zo in de tutorial doen maar als het zover is verander ik het naar mysqli_... en ik gebruik ook nu nog even md5() om te hashen.