init file.....
<?php session_start (); $exceptions = array ('sign up1', 'index', 'activate'); $page = substr(end(explode('/', $_SERVER['SCRIPT_NAME'])), 0, -4); mysql_connect("phplogin113.db.8811650.hostedresource.com","phplogin113","Hookups1"); mysql_select_db("phplogin113"); $path = dirname(__FILE__); include ("{$path}/inc/user.inc.php"); if (isset($_COOKIE['username'], $_COOKIE['passwords']) && isset($_SESSION['username']) === false){ if (valid_credentials($_COOKIE['username'], $_COOKIE['password'])){ $_SESSION['username'] = htmlentities($_COOKIE['username']); setcookie('username', $_COOKIE['username'], time() + 604800); setcookie('password', $_COOKIE['password'], time() + 604800); } } if (in_array($page, $exceptions) === false){ if (isset($_SESSION['username']) === false){ header('Location: index.php'); die(); } } ?>
user.inc. file....
<?php //check if given username exsists in the database function user_exsists($user){ $user = mysql_real_escape_string($user); $total = mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_username` = '{$user}'"); return (mysql_result($total, 0) == '1') ? true : false; } //check if the given username and password combinations are valid function valid_credentials($user, $pass){ $user = mysql_real_escape_string($user); $pass = mysql_real_escape_string($pass); $total= mysql_query("SELECT COUNT(`user_id`) FROM `users` WHERE `user_username` = '{$user}' AND `user_password` = '{$pass}'"); return (mysql_result($total, 0) == '1') ? true : false; } // checks to see is user account is active function is_active($user){ $user = mysql_real_escape_string($user); $sql = "SELECT COUNT (`activations`.`user_id`) FROM`users` INNER JOIN `activations`.`user_id` ON `users`.`user_id` = `activations`.`user_id` WHERE `users`.`user_username` = '{$user}'"; $result = mysql_query($sql); return (mysql_result($result, 0) == '0') ? true : false; } //acctivates the account related to the given activation code function activate_account($aid){ $aid = mysql_real_escape_string($aid); mysql_query("DELETE FROM `activations` WHERE `activation_code` = '{$aid}'"); } //adds a user to the database function add_user($user, $email, $pass){ $user = mysql_real_escape_string(htmlentities($user)); $email = mysql_real_escape_string($email); $pass = sha1($pass); $charset = array_flip(array_merge(range('a', 'z'), range('A', 'Z'), range('0', '9'))); $aid =implode('', array_rand($charset, 10)); $body = <<<EMAIL Thank you for signing up with knowquest. To activate your account, please click the link below http://www.jasonmassieportfolio.com/activate.php?{$aid} EMAIL; mail($email, 'Your new account at Knowquest.com', $body, 'From: admin@knowquest.com'); mysql_query("INSERT INTO `users` (`user_username`, `user_email`, `user_password`) VALUES ('{$user}', '{$email}', '{$pass}')"); $user_id = mysql_insert_id(); mysql_query("INSERT INTO `activations` (`user_id`, `activation_code`) VALUES ({$user_id}, '{$aid}')"); } ?>
activate file....
<?php include('core/init.inc.php'); if (isset($_GET['aid'])){ activate_account($_GET['aid']); } ?>register file.....
<?php include('core/init.inc.php'); $errors = array(); if (isset($_POST['username'], $_POST['password'], $_POST['confirm_password'])){ if (empty ($_POST['username'])){ $errors[] = 'The username cannot be empty!'; } if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false){ $errors[] = 'The email address you entered does not seem to be valid'; } if (empty ($_POST['password']) || empty($_POST['confirm_password'])){ $errors[] = 'The password cannot be empty!'; } if ($_POST['password'] !== $_POST['confirm_password']){ $errors[] = 'The password Varifacation failed!'; } if (user_exsists($_POST['username'])){ $errors[] = 'The username you entered is already taken!'; } if (empty($errors)){ add_user($_POST['username'], $_POST['email'], $_POST['password']); $errors[] = 'You have been regiserd, check your email!'; header('Location: protected.php'); die(); } } ?> <?php if (empty($errors) === false );{ ?> <ul> <?php foreach ($errors as $error){ echo "<li>[$error]</li>"; } ?> </ul> <?php } ?>
please help me with this...... what did i miss....