Problem with script counter.php

Maybe attach an event listener to the button that when clicked, fires off an Ajax request to the PHP script. In the PHP script increment the counter by one and return the value of the counter to your calling script. Then, insert that value into the page in the appropriate place.