How can you determine the calling page in PHP to log it in a database?

To determine the calling page in PHP, you can use the $_SERVER['HTTP_REFERER'] variable, which contains the URL of the page that referred the current page. You can log this information in a database by capturing the value of $_SERVER['HTTP_REFERER'] and inserting it into your database table along with other relevant information.

// Get the calling page URL
$callingPage = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'Unknown';

// Insert the calling page URL into the database
$sql = "INSERT INTO log_table (calling_page, other_column) VALUES ('$callingPage', 'other_value')";
// Execute the SQL query using your database connection