Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start();
- include '_variables.php';
- include 'helpers.php';
- $uname=$_POST['uname'];
- $pword=$_POST['pword'];
- $error_messages = [];
- $conn = new mysqli($servername, $username, $password, $dbname);
- if(!isset($uname) || trim($uname) == '')
- {
- array_push($error_messages, 'Please Enter A Username');
- }
- if(!isset($pword) || trim($pword) == '')
- {
- array_push($error_messages, 'Please Enter A Password');
- }
- //if there are error messages
- if(count($error_messages) > 0){
- //store the error messages in the session
- $_SESSION['regErrors'] = $error_messages;
- //redirect back to the login form
- header('Location: login.php?errors=' . count($error_messages));
- exit();
- }
- //if it reaches this point, that means there are no error messages
- //clear the session of any errors
- unset($_SESSION['regErrors']);
- $result = mysqli_query($conn,"SELECT * FROM Users WHERE username = '$uname' LIMIT 1");
- if ($result->num_rows > 0) {
- $user = mysqli_fetch_assoc($result);
- $hashed_password = $user['password'];
- if (validate_pw($pword, $hashed_password)) {
- $_SESSION['user'] = $user['username'];
- header('Location: profile.php');
- exit();
- }else{
- // I want to turn this into array_push($error_messages)
- // and i know it needs to be before the code where it checks for any
- // errors but if i move this if statement above, what would take its place down here?
- echo "Invalid Password";
- }
- }else{
- // I want to turn this into array_push($error_messages)
- echo "Invalid Username";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement