Anand Sunderraman
Anand Sunderraman

Reputation: 8138

Php polling Is it required

I want to write a php code that displays a html button only till some point of time.

Since php is a scripting language and code get executed only when the html page is rendered,

I was thinking that instead of polling I can just check the time at the time the page is getting rendered. If the current time does not satisfy my condition then I simply won't echo that button else I can echo the button.

Is this approach right or should I do polling ?

Upvotes: 0

Views: 173

Answers (2)

Jage
Jage

Reputation: 8086

Once the page loads, php has no more control. If you have displayed a button, and you want to remove it after a certain time frame, you will need to use javascript anddo some kind of setTimeout() to schedule that. Obviously, the javascript won't be 100% reliable (if someone has js disabled, or a browser not supporting js).

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798784

I don't understand why you would use polling. PHP already has all needed functionality to both check the time and to conditionally output HTML. The only thing that may cause trouble is timezones, but that can be handled by adding an offset to the relevant times.

Upvotes: 1

Related Questions