A
A
adreanov2017-05-03 22:20:57
PHP
adreanov, 2017-05-03 22:20:57

PHP include based on day of the week and time?

Hello!
I have a code on my site that displays content depending on the day of the week:

<? include($_SERVER['DOCUMENT_ROOT'].'/blocks/head.php');?>
<? if (date('l') == 'Sunday') {
    include($_SERVER['DOCUMENT_ROOT'].'/blocks/header-sun.php');
} if (date('l') == 'Monday') {
    include($_SERVER['DOCUMENT_ROOT'].'/blocks/header.php');
} if (date('l') == 'Tuesday') {
    include($_SERVER['DOCUMENT_ROOT'].'/blocks/header.php');
} if (date('l') == 'Wednesday') {
    include($_SERVER['DOCUMENT_ROOT'].'/blocks/header.php');
} if (date('l') == 'Thursday') {
    include($_SERVER['DOCUMENT_ROOT'].'/blocks/header.php');
} if (date('l') == 'Friday') {
    include($_SERVER['DOCUMENT_ROOT'].'/blocks/header-fri.php');
} if (date('l') == 'Saturday') {
    include($_SERVER['DOCUMENT_ROOT'].'/blocks/header-sat.php');
}?>

How to make one more condition: so that the day of the week is output and for example the time is 19:00-09:00?
If it is very difficult, tell me then it's easier - php include by the time interval condition.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Shirshov Alexander, 2017-05-03
@Keanor

Be sure to read about RFI and LFI vulnerabilities.

if (file_exists(DOCROOT . '/blocks/header-' . strtolower(date('l')) . '.php') {
    inclide DOCROOT . '/blocks/header-' . strtolower(date('l')) . '.php';
} else {
    inclide DOCROOT . '/blocks/header.php';
}

if you don’t want to rename files in principle, then strtolower(substr(date('l'), 0, 3))
and, depending on the time, add day or night to the file name

T
Therapyx, 2017-05-04
@Therapyx

But what if you make a knight's move and first initialize the string variable for the week, after which you do just one include. Like include($var + ".php")?
I don’t know the exact syntax, I gave the correct algorithm - it’s up to you))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question