How can hidden fields in a form be used to identify the method of page invocation in PHP?

Hidden fields in a form can be used to identify the method of page invocation in PHP by setting a specific value in the hidden field based on the method used to access the page (e.g., GET or POST). This value can then be checked in the PHP code to determine how the page was accessed.

<form method="post">
    <input type="hidden" name="method" value="post">
    <!-- Other form fields -->
</form>

<form method="get">
    <input type="hidden" name="method" value="get">
    <!-- Other form fields -->
</form>

<?php
if(isset($_POST['method']) && $_POST['method'] == 'post') {
    // Page was accessed using POST method
} elseif(isset($_GET['method']) && $_GET['method'] == 'get') {
    // Page was accessed using GET method
} else {
    // Default behavior
}
?>