SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    May 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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.

    Code:
    <?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"); }
    
    ?>

  2. #2
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Milia View Post
    PHP Code:
    <?php
    $thedays 
    date(d);
    'd' gives the day with leading zeros, not 7 but 07. Use
    PHP Code:
    $thedays date('j'); 
    and don't forget the quotes to make it a string 'j'

    http://www.php.net/manual/en/function.date.php
    Denny Schlesinger
    web services

  3. #3
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,883
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Try this:
    PHP Code:
    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
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  4. #4
    SitePoint Member
    Join Date
    May 2013
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks everyone! It's working now.

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

  5. #5
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,883
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by Milia View Post
    Thanks everyone! It's working now.

    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

    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.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  6. #6
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by captainccs View Post
    'd' gives the day with leading zeros, not 7 but 07.
    And? Whether the $thedays is "7" or "07", the if conditions will do the same thing.
    Salathe
    Software Developer and PHP Manual Author.

  7. #7
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Salathe View Post
    And? Whether the $thedays is "7" or "07", the if conditions will do the same thing.
    Better check, don't you think?
    PHP Code:
    $thedays '07';

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

    says: "Salathe is right"

    Thanks!
    Denny Schlesinger
    web services

  8. #8
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    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
    Code:
    decimal     : [1-9][0-9]*
                | 0
    
    hexadecimal : 0[xX][0-9a-fA-F]+
    
    octal       : 0[0-7]+
    
    binary      : 0b[01]+
    
    integer     : [+-]?decimal
                | [+-]?hexadecimal
                | [+-]?octal
                | [+-]?binary
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  9. #9
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,883
    Mentioned
    74 Post(s)
    Tagged
    6 Thread(s)
    I am under the impression the date only returns two digits so even with a leading zero there will not be a conflict.
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Wolfshade on earning Member of the Month for August 2014

  10. #10
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,397
    Mentioned
    65 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by logic_earth View Post
    You still need to be careful with leading zeros with integers. It could be mistaken for an Octal.
    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.
    Salathe
    Software Developer and PHP Manual Author.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •