xaznbabyx Posted September 12, 2015 Share Posted September 12, 2015 http://hills.ccsf.edu/~schow11/cs130a/groupAssignmentClass.html i did something like this as I was looking through a tutorial on youtube. BUt its no really working and its confusing. Quote Link to comment Share on other sites More sharing options...
requinix Posted September 12, 2015 Share Posted September 12, 2015 What is your question about error handling? What's not working? And when you answer, post your code too. Quote Link to comment Share on other sites More sharing options...
xaznbabyx Posted September 12, 2015 Author Share Posted September 12, 2015 http://pastebin.com/NB3eA3gn sorry about that if (empty($_POST) === false) { $username = $_POST['username'] $password = $_POST['password'] if (empty($username) === true | | empty($password) === true) { $errors[] = 'You need to enter a username and password'; } else if (user_exists($username) === false) { $errors[] 'Your username is incorrect.'; } else if (user_active($username) === false) { $errors[] = 'You have not activated your account!'; } else { if (strlen)($password)) > 20) { $error[] 'Username is too long'; } $login = login($username, $password); if login ==== false) { $errors[] = "That username or password is incorrect. Please try again."; } else if { $_Session['user_id'] = $login; header('Location: index.php'); edit(); } } ?> Quote Link to comment Share on other sites More sharing options...
requinix Posted September 12, 2015 Share Posted September 12, 2015 (edited) Alright. So what is your question about error handling? What's not working? And can I assume you're aware of the syntax errors in your code? And a few other errors... Edited September 12, 2015 by requinix Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 12, 2015 Share Posted September 12, 2015 Yes - you have many silly little errors. Turn on php error checking (as in my signature) and fix the little typos and see what happens. Quote Link to comment Share on other sites More sharing options...
hansford Posted September 13, 2015 Share Posted September 13, 2015 This part of the code is not going to work. if (strlen)($password)) > 20) { // if (strlen($password) > 20) $error[] 'Username is too long'; } $login = login($username, $password); if login ==== false) { // if (login === false) $errors[] = "That username or password is incorrect. Please try again."; } else if { $_Session['user_id'] = $login; header('Location: index.php'); edit(); } Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted September 13, 2015 Share Posted September 13, 2015 And the proper word is $_SESSION all uppercase 1 Quote Link to comment Share on other sites More sharing options...
QuickOldCar Posted September 13, 2015 Share Posted September 13, 2015 Youtube is not the place to be learning, go to php.net I suggest you read everything there and also go through the functions and what they do, when to use them, otherwise you will never learn this. This is a register script just wrote another member, edit it for a login or at least look it over. http://forums.phpfreaks.com/topic/298136-anyone-willing-to-do-a-quick-security-review-or-a-registration-page/?p=1520717 When dealing with passwords should be using password_hash() and password_verify() An attempt to fix this code but should post the rest what you have as well or find a better tutorial with mysqli/pdo and uses password_hash. <?php if (isset($_POST['submit'])) { $errors = array(); if (isset($_POST['username']) && trim($_POST['username']) != '') { $username = trim($_POST['username']); } else { $username = ''; $errors[] = 'username'; } if (isset($_POST['password']) && trim($_POST['password']) != '') { $password = trim($_POST['password']); } else { $password = ''; $errors[] = 'password'; } if (empty($errors)) { $login = login($username, $password); if ($login === false) { $errors[] = "That username or password is incorrect. Please try again."; } else { $_SESSION['user_id'] = $login; //does login function return a name or id? header('Location: index.php'); exit(); } } if (!empty($errors)) { echo "Errors: " . implode($errors,", "); } } ?> Quote Link to comment Share on other sites More sharing options...
hansford Posted September 13, 2015 Share Posted September 13, 2015 I knew I was missing stuff. The code is very difficult to follow. if (strlen)($password)) > 20) { // if (strlen($password) > 20) $error[] 'Username is too long'; } $login = login($username, $password); if login ==== false) { // if (login === false) $errors[] = "That username or password is incorrect. Please try again."; } else if { // No conditional statement. should be only else and not else if $_Session['user_id'] = $login; //as mentioned $_SESSION['user_id'] = $login; header('Location: index.php'); edit(); } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.