1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Rep Power

    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.

    $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"); }
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Washington, USA
    Rep Power
    PHP Code:
    $thedays date('d'); 
    2. Put a special echo inside each if block so you know exactly which branch was executing (because you're using files in different places). Also echo $thedays. What do you get?
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Rep Power

    the "d" makes no difference -- unless you happen to have a constant with this exact name (which would be rather weird). But it's still wrong, of course.

    How do you know the time part "doesn't work"? Have you actually verified the cookie doesn't exist? I've tested the code, and it did exactly what it's supposed to do.

    However, using $_COOKIE values that may not exist isn't good practice, because this generates a lot of notices. You may not see them, but PHP generates them nonetheless. Use isset(). to avoid this. I also find it rather weird to "misuse" external files as some kind of subroutine. Often times this points to a bad application structure and/or a lack of abstraction. But that's just a guess.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".

IMN logo majestic logo threadwatch logo seochat tools logo