How can a visitor counter be displayed in a text field using PHP?

To display a visitor counter in a text field using PHP, you can store the visitor count in a file or a database. Each time a visitor accesses the page, increment the count and display it in the text field.

<?php
$counter_file = 'visitor_count.txt';

// Read the current count from the file
$visitor_count = (file_exists($counter_file)) ? file_get_contents($counter_file) : 0;

// Increment the count
$visitor_count++;

// Write the new count back to the file
file_put_contents($counter_file, $visitor_count);

// Display the count in a text field
echo '<input type="text" value="' . $visitor_count . '" readonly>';
?>