<?
    
require_once('include/functions/valid_email.php');
    require_once(
'include/functions/send_email.php');
    
    
$_email = isset($_POST['email']) ? trim(strval($_POST['email'])) : '';
    
    if (!
$_email || !is_valid_email($_email))
    {
        
make_cookie('notice''Sorry, your email address is not valid.');
        
header('Location: ./?s=password');
        die;
    }
    elseif (!
mysql_num_rows(mysql_query("SELECT email FROM members WHERE email = '" $_email "'")))
    {
        
make_cookie('notice''Sorry, that email address does not exist in our database.');
        
header('Location: ./?s=password');
        die;
    }
    else
    {
        
$cache md5(time() . chr(mt_rand(97122)) . chr(mt_rand(97122)) . chr(mt_rand(97122)) . chr(mt_rand(97122)));
        
mysql_query("REPLACE INTO members_create SET email = " sq($_email) . ", cache = '" $cache "'");
        
$number substr_count(str_replace('www.'''strtolower($_SERVER['HTTP_HOST'])), '.');
        
$url 'http://' . ($number == 'www.' '') . str_replace('www.'''strtolower($_SERVER['HTTP_HOST'])) . '/?s=password_complete&cache=' $cache;
        
$body "You have requested a password update for your account since you seem to have misplaced yours. In order to continue please click the following link:\r\n\r\n\t".$url."\r\n\r\nIf you actually know your password, please do nothing, we will not email you again.";
        
send_email($_email'Forgot Password Email'$body);
    }
    
    
header('Location: ./?s=password_thanks');
    die;
?>