That is the way I once set it up and it has worked ever since (several years). Although I did put it on a Global page that is called into the sidebar a year or so ago. It still worked until recently.
I just tried pasting the code from the php file into an HTML stack and preview shows this where the counter goes. In other words it shows the counter but does not get the data.