Different php include by date

I want to have a different include on a page according to the user’s choice and if there is no choice, the date. The part with cookies to change the included php works, but the page is totally ignoring the date. I want it to be in that order, first considering if the user has made a choice and then if not, it will assign an include depending on the date. The choices are in order, I want the code to stop once it finds a choice that fits and just go with that, so I used “if else”, as there can be more than one choice that is true, thus I thought it might not work with “switch case”. Here’s what I have, the cookies work, but the lines dealing with the date are ignored. I tried putting the day in a variable, but it didn’t make a difference.



<?php

$thedays = date(d);

if ($_COOKIE["confetti"] == "ver1") { include("axel7.php"); }

else if ($_COOKIE["confetti"] == "ver2") { include("yuki7.php"); }

else if ($_COOKIE["confetti"] == "ver3") { include("zel7.php"); }

else if ($_COOKIE["confetti"] == "ver4") { include("yug3.php"); }

else if ($thedays <= 7) { include("yug3.php"); }

else if (($thedays >= 8) && ($thedays <= 14 )) { include("axel7.php"); }

else if (($thedays >= 15) && ($thedays <= 21)) { include("yuki7.php"); }

else if ($thedays >= 22) { include("zel7.php"); }

else { include("axel7.php"); }

?>


‘d’ gives the day with leading zeros, not 7 but 07. Use

$thedays = date('j');

and don’t forget the quotes to make it a string ‘j’

http://www.php.net/manual/en/function.date.php

Try this:


error_reporting(-1);
ini_set("show_errors",1);

echo $thedays=date(d);
echo $thedays=date("d");


Beaten again, responding with a one-fingered tablet is so slow:(

Thanks everyone! It’s working now. :slight_smile:

This was such a rookie mistake… ^^;; But 2 days of experience is a rookie so I guess that’s to be expected. XD

I am pleased we were able to help, we have all been there to get the T-Shirts :slight_smile:

As mentioned using error_reporting and display errors usually screams when errors and warnings are encountered. Having a blank screen without notifications makes it difficult to debug.

And? Whether the $thedays is "7" or "07", the if conditions will do the same thing.

Better check, don’t you think?

$thedays = '07';

if ($thedays <= 7) {
    echo 'Salathe is right';
} else {
    echo 'Salathe is wrong';
}

says: “Salathe is right” :cool:

Thanks!

You still need to be careful with leading zeros with integers. It could be mistaken for an Octal.

http://www.php.net/manual/en/language.types.integer.php

decimal     : [1-9][0-9]*
            | 0

hexadecimal : 0[xX][0-9a-fA-F]+

[COLOR=#ff0000][B]octal       : 0[0-7]+[/B][/COLOR]

binary      : 0b[01]+

integer     : [+-]?decimal
            | [+-]?hexadecimal
            | [+-]?octal
            | [+-]?binary

I am under the impression the date only returns two digits so even with a leading zero there will not be a conflict.

Not in a string unless explicitly declaring that it is octal (e.g. by specifying the base in a function call). More likely is the developer mistaking it for octal.