0) { $items = file($database, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach($items as $line) { list($username, $password, $email, $name, $active) = explode('|', trim($line)); if ($username == $_POST['username'] && $active != "0" && $password == $crypt_pass) { $found = true; $fullname = $name; } } } if($found == false) { header('Location: '.$error_page); exit; } else { if (session_id() == "") { session_start(); } $_SESSION['username'] = $_POST['username']; $_SESSION['fullname'] = $fullname; $_SESSION['expires_by'] = time() + $session_timeout; $_SESSION['expires_timeout'] = $session_timeout; $rememberme = isset($_POST['rememberme']) ? true : false; if ($rememberme) { setcookie('username', $_POST['username'], time() + 3600*24*30); setcookie('password', $_POST['password'], time() + 3600*24*30); } header('Location: '.$success_page); exit; } } $username = isset($_COOKIE['username']) ? $_COOKIE['username'] : ''; $password = isset($_COOKIE['password']) ? $_COOKIE['password'] : ''; if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['form_name']) && $_POST['form_name'] == 'forgotpasswordform') { $email = isset($_POST['email']) ? addslashes($_POST['email']) : ''; $found = false; $items = array(); $success_page = ''; $error_page = basename(__FILE__); $database = './usersdb.php'; if (filesize($database) == 0 || empty($email)) { header('Location: '.$error_page); exit; } else { $items = file($database, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); foreach($items as $line) { list($username, $password, $emailaddress, $fullname, $active) = explode('|', trim($line)); if ($email == $emailaddress && $active != "0") { $found = true; } } } if ($found == true) { $alphanum = array('a','b','c','d','e','f','g','h','i','j','k','m','n','o','p','q','r','s','t','u','v','x','y','z','A','B','C','D','E','F','G','H','I','J','K','M','N','P','Q','R','S','T','U','V','W','X','Y','Z','2','3','4','5','6','7','8','9'); $chars = sizeof($alphanum); $a = time(); mt_srand($a); for ($i=0; $i < 6; $i++) { $randnum = intval(mt_rand(0,55)); $newpassword .= $alphanum[$randnum]; } $crypt_pass = md5($newpassword); $file = fopen($database, 'w'); foreach($items as $line) { $values = explode('|', trim($line)); if ($email == $values[2]) { $values[1] = $crypt_pass; $line = ''; for ($i=0; $i < count($values); $i++) { if ($i != 0) $line .= '|'; $line .= $values[$i]; } } fwrite($file, $line); fwrite($file, "\r\n"); } fclose($file); $mailto = $_POST['email']; $subject = 'New password'; $message = 'Your new password for http://www.yourwebsite.com/ is:'; $message .= $newpassword; $header = "From: webmaster@yourwebsite.com"."\r\n"; $header .= "Reply-To: webmaster@yourwebsite.com"."\r\n"; $header .= "MIME-Version: 1.0"."\r\n"; $header .= "Content-Type: text/plain; charset=utf-8"."\r\n"; $header .= "Content-Transfer-Encoding: 8bit"."\r\n"; $header .= "X-Mailer: PHP v".phpversion(); mail($mailto, $subject, $message, $header); header('Location: '.$success_page); } else { header('Location: '.$error_page); } exit; } ?> Sign in
90 Second Website Builder
Sign up for a new account
Log In
Forgot your password?
Menu