<?php
function user_change_email ($password1,$new_email,$user_name) {
global $feedback,$hidden_hash_var;
if (validate_email($new_email)) {
$hash=md5($new_email.$hidden_hash_var);
file://改變數(shù)據(jù)庫(kù)中確認(rèn)用的無(wú)序碼值,但不改變email
file://發(fā)出一個(gè)帶有新認(rèn)證碼的確認(rèn)email
$user_name=strtolower($user_name);
$password1=strtolower($password1);
$sql="UPDATE user SET confirm_hash='$hash' WHERE user_name='$user_name' AND password='". md5($password1) ."'";
$result=db_query($sql);
if (!$result || db_affected_rows($result) < 1) {
$feedback .= ' ERROR - Incorrect User Name Or Password ';
return false;
} else {
$feedback .= ' Confirmation Sent ';
user_send_confirm_email($new_email,$hash);
return true;
}
} else {
$feedback .= ' New Email Address Appears Invalid ';
return false;
}
}
function user_confirm($hash,$email) {
/*
用戶點(diǎn)擊認(rèn)證email的相關(guān)連接時(shí),連到一個(gè)確認(rèn)的頁(yè)面,該頁(yè)面會(huì)調(diào)用這個(gè)函數(shù),
*/
global $feedback,$hidden_hash_var;
file://verify that they didn't tamper with the email address
$new_hash=md5($email.$hidden_hash_var);
if ($new_hash && ($new_hash==$hash)) {
file://在數(shù)據(jù)庫(kù)中找出這個(gè)記錄
$sql="SELECT * FROM user WHERE confirm_hash='$hash'";
$result=db_query($sql);
if (!$result || db_numrows($result) < 1) {
$feedback .= ' ERROR - Hash Not Found ';
return false;
} else {
file://確認(rèn)email,并且設(shè)置帳號(hào)為已經(jīng)激活
$feedback .= ' User Account Updated - You Are Now Logged In ';
user_set_tokens(db_result($result,0,'user_name'));
$sql="UPDATE user SET email='$email',is_confirmed='1' WHERE confirm_hash='$hash'";
$result=db_query($sql);
return true;
}
} else {
$feedback .= ' HASH INVALID - UPDATE FAILED ';
return false;
}
}
function user_send_confirm_email($email,$hash) {
/*
這個(gè)函數(shù)在首次注冊(cè)或者改變email地址時(shí)使用
*/
$message = "Thank You For Registering at Company.com".
"nSimply follow this link to confirm your registration: ".
"nnhttp://www.company.com/account/confirm.php?hash=$hash&email=". urlencode($email). "nnOnce you confirm, you can use the services on PHPBuilder.";
mail ($email,'Registration Confirmation',$message,'From: noreply@company.com');
}
?>