0
I want my site to only appear one page on Thursdays, is there any way to do that ? 'Cause I want a feature of him online on Thursday from 9 to 12 o'clock in the day. Help me !
0
I want my site to only appear one page on Thursdays, is there any way to do that ? 'Cause I want a feature of him online on Thursday from 9 to 12 o'clock in the day. Help me !
0
You can do this in many ways. The simplest way I know would be:
// Hora de abertura do site.
$openHours = new DateTime("09:00:00");
// Hora de fechamento do site.
$closeHours = new DateTime("12:00:00");
// Hora atual.
$currentHours = new DateTime("now");
// Verifica se é quinta e
// se a hora atual é maior que o horário de abertura e
// se a hora atual é menor que o horário de fechamento.
if (date('N') == 4 && $currentHours >= $openHours && $currentHours <= $closeHours) {
// Código...
}
You can also do so:
Recommend only if displaying any HTML snippet, do not necessarily start with DOCTYPE, or the html tag, can be anything, even as a simple text!.
// Hora de abertura do site.
$openHours = new DateTime("09:00:00");
// Hora de fechamento do site.
$closeHours = new DateTime("12:00:00");
// Hora atual.
$currentHours = new DateTime("now");
// Verifica se é quinta e
// se a hora atual é maior que o horário de abertura e
// se a hora atual é menor que o horário de fechamento.
if (date('N') == 4 && $currentHours >= $openHours && $currentHours <= $closeHours): ?>
<!DOCTYPE html>
<html>
...
<?php endif;
The difference was in the probation block if
, that instead of the keys {}
, if used :
and :endif;
.
If you want to display something, or do something, you can use a Else normally.
if (...) {
// Código...
} else {
// Código para quando não estiver disponível.
}
or
if (...): ?>
<div></div>
<?php else: ?>
<p>Site não está disponível!</p>
<?php endif; ?>
Or even if you prefer, you can throw an error 404 as if the page really didn’t exist:
if (...) {
// Código...
} else {
header("HTTP/1.0 404 Not Found");
}
I recommend reading:
Browser other questions tagged php
You are not signed in. Login or sign up in order to post.
The whole or only part of the site?
– Sam
On the location you want to provide a link to the screen makes a comparison of the day of the week of the current date with Thursday
– Caique Romero