Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- // Connect to database
- $conn=mysql_connect(DB_HOST,DB_USER,DB_PASS);
- mysql_select_db(DB_BASE);
- // Instantiate Classes
- $login = new Login();
- //$session = new Sessions();
- // Simple function to sanitize form input
- function protect($string) {
- $newString = trim(mysql_escape_string($string));
- return $newString;
- }
- // Determine if loginSubmit has been set and the value of login is 1
- if (isset($_POST['loginSubmit']) && $_POST['login'] == 1) {
- // Define $errors variable as an array
- $errors = array();
- // Determine if username or password is empty; if yes, assign error message
- if (empty($_POST['username'])) {
- $errors['username'] = 'You must provide a username';
- }
- if (empty($_POST['password'])) {
- $errors['password'] = 'You must provide a password';
- }
- // If there are no errors, begin functions to log user in
- if (empty($errors)) {
- // Sanitize data input
- $username = protect($_POST['username']);
- $password = protect($_POST['password']);
- // Check that user exists
- $userExists = $login->loginExists($username, $password);
- if ($userExists['userCount'] == 1) {
- // If the user exists, set session variables and redirect user to the appropriate dashboard
- header("Location:main.php?affiliateID=$affiliateID");
- }
- }
- else {
- // If user cannot be logged in, display error message
- $page->contentSet('<p class="error">There was an error logging you in. Please try again.</p>');
- }
- }
- ?>
Add Comment
Please, Sign In to add comment