r/PHPhelp • u/[deleted] • Aug 21 '20
Launch countdown for a website.
I have a website that launches on 28th @ 12:00 gmt.
Until that time, I want my page to display a countdown page.
Currently I have a html -page with a javascript -snippet that displays the countdown,
and when the counter reaches zero, it redirects to the real page.
Problem is that my javascript counter uses date(), which gets the time from client machine,
so you can fake your system time and get past the countdown- page.
What would be an efficient and sure way to prevent anyone from viewing my page before launch?
6
u/Amunium Aug 21 '20
Does that mean the website is actually running and completely available, you've just hidden it with some Javascript? That's a fundamentally bad way of doing that. Anyone with a script-blocker or the tiniest bit of knowledge of script is going to be able to get around that, not to mention that robots and web crawlers can see things they shouldn't.
You should only have the counter page available, the rest should either not exist until the set date, or be locked off with server side technology - e.g. PHP. Then it won't matter if someone tries to get around it.
3
u/jurgonaut Aug 21 '20
An easy solution would be to define yourself the date used. Store it somewhere on the backend and let javascript use that for the countdown.
14
u/g105b Aug 21 '20
Output the page with PHP, where PHP shows the countdown, then use JavaScript to do the ticking down using the starting point provided by PHP.
When the counter reaches 0, make JavaScript reload the page itself rather than redirecting. Then back in PHP you can do the redirect if the countdown is 0, but this being done on the server will prevent client side hacks.