get_result ( ); $row = $result->fetch_assoc ( ); if ( ! $row ) { include ( 'errors/404.html' ); } else { include ( 'includes/redirect.html' ); echo ( '' ); } } elseif ( isset ( $_REQUEST [ 'username' ] ) && isset ( $_REQUEST [ 'password' ] ) ) { $username = $_REQUEST [ 'username' ]; $password = $_REQUEST [ 'password' ]; $db_connection = db_connect ( ); $statement = db_prepare ( $db_connection, "SELECT users.id FROM users WHERE users.username = ? AND users.password = ?" ); $parameters = [ [ "ss" ], [ &$username, &$password ], ]; db_bind ( $statement, $parameters ); db_execute ( $statement ); $result = $statement->get_result ( ); $row = $result->fetch_assoc ( ); if ( ! $row ) { header ( 'Content-Type: application/json' ); $response = [ 'status' => 401, 'error_message' => 'Username or password not correct.', ]; echo ( json_encode ( $response ) ); } else { $_SESSION [ 'user_id' ] = $row [ 'id' ]; header ( 'Content-Type: application/json' ); $response = [ 'status' => 200, 'message' => 'Authentication succesfully executed.', ]; echo ( json_encode ( $response ) ); } } elseif ( isset ( $_GET [ 'logout' ] ) ) { $_SESSION = array ( ); session_destroy ( ); header ( "Location: " . $_SERVER [ 'SCRIPT_NAME' ] ); } else { if ( ! isset ( $_SESSION [ 'user_id' ] ) ) { ?>