How can PHP be used to detect and respond to user input within a web application?

To detect and respond to user input within a web application using PHP, you can use superglobal arrays like $_GET, $_POST, and $_REQUEST to access form data submitted by the user. You can then use conditional statements to check for specific input values and execute corresponding actions or responses.

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $username = $_POST['username'];
    
    if ($username == "admin") {
        echo "Welcome, admin!";
    } else {
        echo "Hello, " . $username . "!";
    }
}