在PHP中使用退出的好习惯

I'm making a simple login system and I'm using exit but I'm not sure is this way its the correct way to use exit.

<?php

    if(fromLogin()){
        session_start();
        error_reporting(0);

        $username = htmlspecialchars($_POST['username']);
        $password = htmlspecialchars($_POST['password']);

        $mysqli = new mysqli('localhost', 'root', '12345', 'seocom');

        if ($mysqli->connect_errno) {
            echo "connection_error";
            exit;
        }
        $sql = "SELECT username, password FROM login WHERE username = '$username'";
        if (!$result = $mysqli->query($sql)) {
            echo "connection_error";
            exit;  
        }
        if ($result->num_rows === 0 ){
            echo "user_error"; 
            exit;
        }  

        $user_pass = $result->fetch_assoc();
        if($user_pass['username'] == $username && md5($password) == $user_pass['password']){
            $_SESSION['logued'] = true;
            $_SESSION['username'] = $username;
            echo "logued";
        }else{
            echo "user_error"; 
        }
        $result->free();
        $mysqli->close();
    }else{
        header("Location: login.html");
        exit;
    }

    //comprueba si viene de login.html
    function fromLogin(){
        return $_SERVER['HTTP_REFERER'] == "http://".$_SERVER['SERVER_NAME']."/seocom_login/login.html";
    }

This is a correct way or I should use nested if and else instead? I m not sure if call exit on every possible error is a good approach to use the exit function.

In procedural code like in your case, it is bad practice. Because exit endpoints really increase read, debug and refactoring complexity.

Sometimes in functions, you can use "return" to stop executing function code.

p.s.

You can think about decoupling your logic on atomic functions. This decrease reading complexity. Or you can think about OOP methods.