WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Enter Page (32 posts)

  1. Finnaus
    Member
    Posted 1 year ago #

    Hi,
    I am wanting to create a enter page on my website so that someone goes to my website they enter their birth date and if they are a certain age, it lets them enter into the website, and if not, they get redirected back to a previous page or google or something like that.

    Thanks!

  2. Dandy Plow
    Member
    Posted 1 year ago #

    Take a look--basically uses a form (which takes up the bottom portion of the code) to request visitor's month, date, and year of birth. When the form is submitted, that's when the first part of the code is run. The $minimumagetoviewsite variable can be changed to whatever minimum age you're looking for, in years.

    If the year of their birth is more than 18 years (as the $minimumagetoviewsite is currently set to) before the current year, they're accepted. If it's less, they're not. If it's the year in which they turn 18, the code checks if the month of their birth has passed, if not, they're rejected, if it has, they're accepted, if it's the same as the current month, it looks at the date, etc...

    Good luck!

    <html>
    <?php if($_POST['submitted'] != "") { ?>
    
    <?php 
    
    $minimumagetoviewsite = 18;
    $birthmonth = $_POST['month'];
    $birthdate = $_POST['date'];
    $birthyear = $_POST['year'];
    $todaysmonth = date("n");
    $todaysdate = date("j");
    $todaysyear = date("Y"); 
    
    if(($birthyear + $minimumagetoviewsite)<$todaysyear) {
    $yearcheck = "okay";
    } else if(($birthyear + $minimumagetoviewsite)>$todaysyear) {
    $yearcheck = "no";
    } else {
    $yearcheck = "same";
    }
    if($birthmonth < $todaysmonth) {
    $monthcheck = "okay";
    } else if($birthmonth > $todaysmonth) {
    $monthcheck = "no";
    } else {
    $monthcheck = "same";
    }
    if($birthdate <= $todaysdate) {
    $datecheck = "okay";
    } else {
    $datecheck = "no";
    };
    if ($yearcheck=="okay") {
    $agecheck = "pass";
    } else if ($yearcheck=="no") {
    $agecheck = "fail";
    } else {
    if ($monthcheck=="okay") {
    $agecheck = "pass";
    } else if ($monthcheck=="no") {
    $agecheck = "fail";
    } else {
    if ($datecheck=="okay") {
    $agecheck = "pass";
    } else if ($datecheck=="no") {
    $agecheck = "fail";
    }
    }
    }
    
    if($agecheck=="pass") { ?>
    
    This is where all the code goes for someone who's the right age
    
    <?php } else { ?>
    
    This is where all the code goes for someone who's too young
    
    <?php }; ?>
    
    <?php } else { ?>
    <form method="post" action="">
    <select name="month">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    </select>
    <select name="date">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>
    </select>
    <select name="year">
    <option>1920</option>
    <option>1921</option>
    <option>1922</option>
    <option>1923</option>
    <option>1924</option>
    <option>1925</option>
    <option>1926</option>
    <option>1927</option>
    <option>1928</option>
    <option>1929</option>
    <option>1930</option>
    <option>1931</option>
    <option>1932</option>
    <option>1933</option>
    <option>1934</option>
    <option>1935</option>
    <option>1936</option>
    <option>1937</option>
    <option>1938</option>
    <option>1939</option>
    <option>1940</option>
    <option>1941</option>
    <option>1942</option>
    <option>1943</option>
    <option>1944</option>
    <option>1945</option>
    <option>1946</option>
    <option>1947</option>
    <option>1948</option>
    <option>1949</option>
    <option>1950</option>
    <option>1951</option>
    <option>1952</option>
    <option>1953</option>
    <option>1954</option>
    <option>1955</option>
    <option>1956</option>
    <option>1957</option>
    <option>1958</option>
    <option>1959</option>
    <option>1960</option>
    <option>1961</option>
    <option>1962</option>
    <option>1963</option>
    <option>1964</option>
    <option>1965</option>
    <option>1966</option>
    <option>1967</option>
    <option>1968</option>
    <option>1969</option>
    <option>1970</option>
    <option>1971</option>
    <option>1972</option>
    <option>1973</option>
    <option>1974</option>
    <option>1975</option>
    <option>1976</option>
    <option>1977</option>
    <option>1978</option>
    <option>1979</option>
    <option>1980</option>
    <option>1981</option>
    <option>1982</option>
    <option>1983</option>
    <option>1984</option>
    <option>1985</option>
    <option>1986</option>
    <option>1987</option>
    <option>1988</option>
    <option>1989</option>
    <option>1990</option>
    <option>1991</option>
    <option>1992</option>
    <option>1993</option>
    <option>1994</option>
    <option>1995</option>
    <option>1996</option>
    <option>1997</option>
    <option>1998</option>
    <option>1999</option>
    <option>2000</option>
    <option>2001</option>
    <option>2002</option>
    <option>2003</option>
    <option>2004</option>
    <option>2005</option>
    <option>2006</option>
    <option>2007</option>
    <option>2008</option>
    <option>2009</option>
    <option>2010</option>
    <option>2011</option>
    <option>2012</option>
    </select>
    <input type="hidden" name="submitted" value="yes">
    <input type="submit" name="submit" value="verify">
    </form>
    <?php }; ?>
  3. Finnaus
    Member
    Posted 1 year ago #

    Thank you so much Dandy! I just have one more question, is there a way I can put a background image on this, and make it a page template so that there is nothing on the screen when you go to the website exempt the age verify and the background image.

    Thanks again!

  4. Dandy Plow
    Member
    Posted 1 year ago #

    Hmm... What I would do is get into your ftp and find wp-content/themes/the theme you use.

    Create a file called ageverify.php (or whatever-you-want-to-call-it.php), and make the contents of it:

    <?php if($_POST['submitted'] != "") { ?>
    
    <?php 
    
    $minimumagetoviewsite = 18;
    $birthmonth = $_POST['month'];
    $birthdate = $_POST['date'];
    $birthyear = $_POST['year'];
    $todaysmonth = date("n");
    $todaysdate = date("j");
    $todaysyear = date("Y"); 
    
    if(($birthyear + $minimumagetoviewsite)<$todaysyear) {
    $yearcheck = "okay";
    } else if(($birthyear + $minimumagetoviewsite)>$todaysyear) {
    $yearcheck = "no";
    } else {
    $yearcheck = "same";
    }
    if($birthmonth < $todaysmonth) {
    $monthcheck = "okay";
    } else if($birthmonth > $todaysmonth) {
    $monthcheck = "no";
    } else {
    $monthcheck = "same";
    }
    if($birthdate <= $todaysdate) {
    $datecheck = "okay";
    } else {
    $datecheck = "no";
    };
    if ($yearcheck=="okay") {
    $agecheck = "pass";
    } else if ($yearcheck=="no") {
    $agecheck = "fail";
    } else {
    if ($monthcheck=="okay") {
    $agecheck = "pass";
    } else if ($monthcheck=="no") {
    $agecheck = "fail";
    } else {
    if ($datecheck=="okay") {
    $agecheck = "pass";
    } else if ($datecheck=="no") {
    $agecheck = "fail";
    }
    }
    }
    
    if($agecheck=="pass") {
    include(TEMPLATEPATH . '/index.php'); ?>
    
    <?php } else { ?>
    
    This is where all the code goes for someone who's too young
    
    <?php }; ?>
    
    <?php } else { ?>
    <form method="post" action="">
    <select name="month">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    </select>
    <select name="date">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>
    </select>
    <select name="year">
    <option>1920</option>
    <option>1921</option>
    <option>1922</option>
    <option>1923</option>
    <option>1924</option>
    <option>1925</option>
    <option>1926</option>
    <option>1927</option>
    <option>1928</option>
    <option>1929</option>
    <option>1930</option>
    <option>1931</option>
    <option>1932</option>
    <option>1933</option>
    <option>1934</option>
    <option>1935</option>
    <option>1936</option>
    <option>1937</option>
    <option>1938</option>
    <option>1939</option>
    <option>1940</option>
    <option>1941</option>
    <option>1942</option>
    <option>1943</option>
    <option>1944</option>
    <option>1945</option>
    <option>1946</option>
    <option>1947</option>
    <option>1948</option>
    <option>1949</option>
    <option>1950</option>
    <option>1951</option>
    <option>1952</option>
    <option>1953</option>
    <option>1954</option>
    <option>1955</option>
    <option>1956</option>
    <option>1957</option>
    <option>1958</option>
    <option>1959</option>
    <option>1960</option>
    <option>1961</option>
    <option>1962</option>
    <option>1963</option>
    <option>1964</option>
    <option>1965</option>
    <option>1966</option>
    <option>1967</option>
    <option>1968</option>
    <option>1969</option>
    <option>1970</option>
    <option>1971</option>
    <option>1972</option>
    <option>1973</option>
    <option>1974</option>
    <option>1975</option>
    <option>1976</option>
    <option>1977</option>
    <option>1978</option>
    <option>1979</option>
    <option>1980</option>
    <option>1981</option>
    <option>1982</option>
    <option>1983</option>
    <option>1984</option>
    <option>1985</option>
    <option>1986</option>
    <option>1987</option>
    <option>1988</option>
    <option>1989</option>
    <option>1990</option>
    <option>1991</option>
    <option>1992</option>
    <option>1993</option>
    <option>1994</option>
    <option>1995</option>
    <option>1996</option>
    <option>1997</option>
    <option>1998</option>
    <option>1999</option>
    <option>2000</option>
    <option>2001</option>
    <option>2002</option>
    <option>2003</option>
    <option>2004</option>
    <option>2005</option>
    <option>2006</option>
    <option>2007</option>
    <option>2008</option>
    <option>2009</option>
    <option>2010</option>
    <option>2011</option>
    <option>2012</option>
    </select>
    <input type="hidden" name="submitted" value="yes">
    <input type="submit" name="submit" value="verify">
    </form>
    <?php }; ?>

    The only different between this code and the code I gave you earlier is that now, if the person passes the age test, instead of just spitting out "This is where all the code goes for someone who's the right age", it uses:

    <?php include(TEMPLATEPATH . '/index.php'); ?>

    which says to load your "Main Index" page.

    Now, all you need to do is go in and create a page and choose the template ageverify.php, or whatever you chose to call it. Then, on your dashboard, go to 'settings'>>'reading' and choose "a static page" for "front page displays" and select the page you just created from the drop down.

    So now, anytime someone goes to http://www.yoursite.com, they'll be shown the age verification. If they pass, they'll get sent to your main index page.

    I left out the header from your age verify page, since I'm assuming you'll have things in there that you don't want on that page. As a result, the css won't get called in, so you'd need to style all of this code manually in order to have a background image. You can do that pretty simply by just adding this to the top of your age verify page:

    <html>
    <body style="background: url('http://www.yoursite.com/backgroundimage.jpg');">
  5. Finnaus
    Member
    Posted 1 year ago #

    This is so great, thank you so much for helping a noob out XD

    Just one last question, is it possible to align the boxes and verify button on the bottom right of the screen?

    I'm trying to get it to look like this:

    http://i.imgur.com/LofdD.jpg

    and this is what it currently looks like:

    http://i.imgur.com/0dGxp.jpg

    Also if you don't have time to help me thats totally fine, I'll find another way to do it.

    Thanks again.

  6. Dandy Plow
    Member
    Posted 1 year ago #

    Definitely. Right above:

    <form method="post" action="">

    add:

    <div style="position: absolute; bottom: 0px; right: 0px">

    Then, near the very bottom, right after:

    </form>

    add:

    </div>

    That encapsulates the whole form (boxes and verify button) in a container which has been defined as being 0 pixels from the right side of the window, and 0 pixels from the bottom of the window. So if you find you want it further in or up, just change the "bottom: 0px" to "bottom: 25px", or whetever number. Same for "right: 0px".

    Tweak and see what you come up with!

  7. Finnaus
    Member
    Posted 1 year ago #

    One last thing (hopefully)

    When the age is not over 21 (which is what I set it too) it still goes to the website, even when I try to put something like a redirect when it's not over 21.

    Thanks again, this is looking really good.

    -Finn

  8. Dandy Plow
    Member
    Posted 1 year ago #

    Couple things to try one-by-one and then test:

    1) Make sure line says EXACTLY: $minimumagetoviewsite = 21;

    2) Try removing <div style="position: absolute; bottom: 0px; right: 0px"> and </div>

    3) Where it originally said "This is where all the code goes for someone who's too young", replace with <?php break; ?>, which would make it very clear on a test if the right reaction was being triggered by someone being too young.

  9. Finnaus
    Member
    Posted 1 year ago #

    Alright, so here's what I think is happening.
    Weather you're over 21 or not, it redirects you to a 404 page not found.
    I'm doing something wrong I know XD

    -Finn

  10. Dandy Plow
    Member
    Posted 1 year ago #

    Okay, so change

    if($agecheck=="pass") {
    include(TEMPLATEPATH . '/index.php'); ?>
    
    <?php } else { ?>
    
    This is where all the code goes for someone who's too young
    
    <?php }; ?>

    to

    if($agecheck=="pass") { ?>
    This is where all the code goes for someone who's old enough
    
    <?php } else { ?>
    
    This is where all the code goes for someone who's too young
    
    <?php }; ?>

    If that works, we know the error lies with include(TEMPLATEPATH . '/index.php');.

    What's supposed to be happening is that wordpress shows the new age verification page as the default home page. That page is one you created in wp-content/name-of-your-theme/. If someone goes to your site, they see the verification page and enter their birth date. If it's over 21, the include(TEMPLATEPATH . '/index.php'); line of could should load your actual Main Index page.

  11. Finnaus
    Member
    Posted 1 year ago #

    Nope, it still brings me to a 404 page not found.....

  12. Finnaus
    Member
    Posted 1 year ago #

    Is there a place where I should put a URL to redirect to if $agecheck=pass or something?

  13. Dandy Plow
    Member
    Posted 1 year ago #

    what does your browser's url say when you get the 404?

  14. Dandy Plow
    Member
    Posted 1 year ago #

    the thing that matters most is the bit after http://www.yoursite.com, so you don't have to include the full url. Just wondering in terms of /index.php, or whatever

  15. Finnaus
    Member
    Posted 1 year ago #

    nothing, it's just the url of the website.

  16. Dandy Plow
    Member
    Posted 1 year ago #

    Okay, so you go to http://www.yoursite.com and you see the age verification perfectly. No problems. But you submit the age, and you get 404.

    Try this--Find <form method="post" action="">. Action states what page the user should be directed to when they submit the form. I'm wondering if the fact that WordPress is automatically directing people from http://www.yoursite.com to http://www.yoursite.com/ageverify.php is messing things up.

    So change <form method="post" action=""> to <form method="post" action="http://www.yoursite.com/index.php">

  17. Finnaus
    Member
    Posted 1 year ago #

    Ok so I had it redirect to /about and once I hit enter it still says 404 error even though after the url it says /about

  18. Dandy Plow
    Member
    Posted 1 year ago #

    Can you get to /about directly? If you type it into your browser's address bar, is it a page you can access? Or do you get a 404 then, too?

  19. Finnaus
    Member
    Posted 1 year ago #

    I can access it directly. This is so weird.....

  20. Finnaus
    Member
    Posted 1 year ago #

    This is the code I'm currently using:

    <?php
    /*
    Template Name: enter
    */
    ?>
    <?php if($_POST['submitted'] != "") { ?>
    
    <?php 
    
    $minimumagetoviewsite = 21;
    $birthmonth = $_POST['month'];
    $birthdate = $_POST['date'];
    $birthyear = $_POST['year'];
    $todaysmonth = date("n");
    $todaysdate = date("j");
    $todaysyear = date("Y"); 
    
    if(($birthyear + $minimumagetoviewsite)<$todaysyear) {
    $yearcheck = "okay";
    } else if(($birthyear + $minimumagetoviewsite)>$todaysyear) {
    $yearcheck = "no";
    } else {
    $yearcheck = "same";
    }
    if($birthmonth < $todaysmonth) {
    $monthcheck = "okay";
    } else if($birthmonth > $todaysmonth) {
    $monthcheck = "no";
    } else {
    $monthcheck = "same";
    }
    if($birthdate <= $todaysdate) {
    $datecheck = "okay";
    } else {
    $datecheck = "no";
    };
    if ($yearcheck=="okay") {
    $agecheck = "pass";
    } else if ($yearcheck=="no") {
    $agecheck = "fail";
    } else {
    if ($monthcheck=="okay") {
    $agecheck = "pass";
    } else if ($monthcheck=="no") {
    $agecheck = "fail";
    } else {
    if ($datecheck=="okay") {
    $agecheck = "pass";
    } else if ($datecheck=="no") {
    $agecheck = "fail";
    }
    }
    }
    
    if($agecheck=="pass") { ?>
    This is where all the code goes for someone who's old enough
    
    <?php } else { ?>
    
    This is where all the code goes for someone who's too young
    
    <?php }; ?>
    
    <?php } else { ?>
    <div style="position: absolute; bottom: 150px; right: 300px">
    <form method="post" action="http://realmccoyspirits.com/about/">
    <select name="month">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    </select>
    <select name="date">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>
    </select>
    <select name="year">
    <option>1920</option>
    <option>1921</option>
    <option>1922</option>
    <option>1923</option>
    <option>1924</option>
    <option>1925</option>
    <option>1926</option>
    <option>1927</option>
    <option>1928</option>
    <option>1929</option>
    <option>1930</option>
    <option>1931</option>
    <option>1932</option>
    <option>1933</option>
    <option>1934</option>
    <option>1935</option>
    <option>1936</option>
    <option>1937</option>
    <option>1938</option>
    <option>1939</option>
    <option>1940</option>
    <option>1941</option>
    <option>1942</option>
    <option>1943</option>
    <option>1944</option>
    <option>1945</option>
    <option>1946</option>
    <option>1947</option>
    <option>1948</option>
    <option>1949</option>
    <option>1950</option>
    <option>1951</option>
    <option>1952</option>
    <option>1953</option>
    <option>1954</option>
    <option>1955</option>
    <option>1956</option>
    <option>1957</option>
    <option>1958</option>
    <option>1959</option>
    <option>1960</option>
    <option>1961</option>
    <option>1962</option>
    <option>1963</option>
    <option>1964</option>
    <option>1965</option>
    <option>1966</option>
    <option>1967</option>
    <option>1968</option>
    <option>1969</option>
    <option>1970</option>
    <option>1971</option>
    <option>1972</option>
    <option>1973</option>
    <option>1974</option>
    <option>1975</option>
    <option>1976</option>
    <option>1977</option>
    <option>1978</option>
    <option>1979</option>
    <option>1980</option>
    <option>1981</option>
    <option>1982</option>
    <option>1983</option>
    <option>1984</option>
    <option>1985</option>
    <option>1986</option>
    <option>1987</option>
    <option>1988</option>
    <option>1989</option>
    <option>1990</option>
    <option>1991</option>
    <option>1992</option>
    <option>1993</option>
    <option>1994</option>
    <option>1995</option>
    <option>1996</option>
    <option>1997</option>
    <option>1998</option>
    <option>1999</option>
    <option>2000</option>
    <option>2001</option>
    <option>2002</option>
    <option>2003</option>
    <option>2004</option>
    <option>2005</option>
    <option>2006</option>
    <option>2007</option>
    <option>2008</option>
    <option>2009</option>
    <option>2010</option>
    <option>2011</option>
    <option>2012</option>
    </select>
    <input type="hidden" name="submitted" value="yes">
    <input type="submit" name="submit" value="verify">
    </form>
    </div>
    <?php }; ?>
    <html>
    <body style="background: url('http://realmccoyspirits.com/wp-content/uploads/2012/12/McCoyWebOpenBlackBottleLineBlack2.jpg');">
    <style=bgcolor="#000000">
  21. Dandy Plow
    Member
    Posted 1 year ago #

    Okay--I don't know if this is going to make a difference, but right off the bat, the

    <html>
    <body style="background: url('http://realmccoyspirits.com/wp-content/uploads/2012/12/McCoyWebOpenBlackBottleLineBlack2.jpg');">
    <style=bgcolor="#000000">

    is not right. Needs to be

    <html>
    <body style="background: #000000 url('http://realmccoyspirits.com/wp-content/uploads/2012/12/McCoyWebOpenBlackBottleLineBlack2.jpg');">

    and should not be at the bottom. It's opening code that should be above

    <?php if($_POST['submitted'] != "") { ?>

  22. Finnaus
    Member
    Posted 1 year ago #

    Ugh, it's still not working.....
    Sorry for taking up so much of your time.

  23. Dandy Plow
    Member
    Posted 1 year ago #

    I'M sorry for giving you buggy code! I've got a better idea to start from scratch that ought to get you all set--I'll post tomorrow morning

  24. Dandy Plow
    Member
    Posted 1 year ago #

    Undo everything I've had you do. Get rid of the age verify page, and on your dashboard, go to 'settings'>>'reading' and return the front page displays setting to "your latest posts".

    Now, go to your header file. Directly under </head>

    Copy and paste this code:

    <?php if (!(isset($_COOKIE["AgeVerify"]))) { ?>
    <?php if($_POST['submitted'] != "") { ?>
    
    <?php 
    
    $minimumagetoviewsite = 21;
    $birthmonth = $_POST['month'];
    $birthdate = $_POST['date'];
    $birthyear = $_POST['year'];
    $todaysmonth = date("n");
    $todaysdate = date("j");
    $todaysyear = date("Y"); 
    
    if(($birthyear + $minimumagetoviewsite)<$todaysyear) {
    $yearcheck = "okay";
    } else if(($birthyear + $minimumagetoviewsite)>$todaysyear) {
    $yearcheck = "no";
    } else {
    $yearcheck = "same";
    }
    if($birthmonth < $todaysmonth) {
    $monthcheck = "okay";
    } else if($birthmonth > $todaysmonth) {
    $monthcheck = "no";
    } else {
    $monthcheck = "same";
    }
    if($birthdate <= $todaysdate) {
    $datecheck = "okay";
    } else {
    $datecheck = "no";
    };
    if ($yearcheck=="okay") {
    $agecheck = "pass";
    } else if ($yearcheck=="no") {
    $agecheck = "fail";
    } else {
    if ($monthcheck=="okay") {
    $agecheck = "pass";
    } else if ($monthcheck=="no") {
    $agecheck = "fail";
    } else {
    if ($datecheck=="okay") {
    $agecheck = "pass";
    } else if ($datecheck=="no") {
    $agecheck = "fail";
    }
    }
    }
    
    if($agecheck=="pass") { ?>
    
    <?php setcookie("AgeVerify", $value, time()+3600); ?>
    
    <?php } else { ?>
    
    This is where all the code goes for someone who's too young
    
    <?php }; ?>
    
    <?php } else { ?>
    <div style="position: absolute; bottom: 150px; right: 300px">
    <form method="post" action="">
    <select name="month">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    </select>
    <select name="date">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>
    </select>
    <select name="year">
    <option>1920</option>
    <option>1921</option>
    <option>1922</option>
    <option>1923</option>
    <option>1924</option>
    <option>1925</option>
    <option>1926</option>
    <option>1927</option>
    <option>1928</option>
    <option>1929</option>
    <option>1930</option>
    <option>1931</option>
    <option>1932</option>
    <option>1933</option>
    <option>1934</option>
    <option>1935</option>
    <option>1936</option>
    <option>1937</option>
    <option>1938</option>
    <option>1939</option>
    <option>1940</option>
    <option>1941</option>
    <option>1942</option>
    <option>1943</option>
    <option>1944</option>
    <option>1945</option>
    <option>1946</option>
    <option>1947</option>
    <option>1948</option>
    <option>1949</option>
    <option>1950</option>
    <option>1951</option>
    <option>1952</option>
    <option>1953</option>
    <option>1954</option>
    <option>1955</option>
    <option>1956</option>
    <option>1957</option>
    <option>1958</option>
    <option>1959</option>
    <option>1960</option>
    <option>1961</option>
    <option>1962</option>
    <option>1963</option>
    <option>1964</option>
    <option>1965</option>
    <option>1966</option>
    <option>1967</option>
    <option>1968</option>
    <option>1969</option>
    <option>1970</option>
    <option>1971</option>
    <option>1972</option>
    <option>1973</option>
    <option>1974</option>
    <option>1975</option>
    <option>1976</option>
    <option>1977</option>
    <option>1978</option>
    <option>1979</option>
    <option>1980</option>
    <option>1981</option>
    <option>1982</option>
    <option>1983</option>
    <option>1984</option>
    <option>1985</option>
    <option>1986</option>
    <option>1987</option>
    <option>1988</option>
    <option>1989</option>
    <option>1990</option>
    <option>1991</option>
    <option>1992</option>
    <option>1993</option>
    <option>1994</option>
    <option>1995</option>
    <option>1996</option>
    <option>1997</option>
    <option>1998</option>
    <option>1999</option>
    <option>2000</option>
    <option>2001</option>
    <option>2002</option>
    <option>2003</option>
    <option>2004</option>
    <option>2005</option>
    <option>2006</option>
    <option>2007</option>
    <option>2008</option>
    <option>2009</option>
    <option>2010</option>
    <option>2011</option>
    <option>2012</option>
    </select>
    <input type="hidden" name="submitted" value="yes">
    <input type="submit" name="submit" value="verify">
    </form>
    </div>
    <?php }} else { ; ?>

    Then, go into your footer file. Directly above </body>

    paste:

    <?php }; ?>

    The earlier code I gave you I only tested successfully outside of a WordPress build. I think its pretty permalinks might be futzing with the form posting. This new stuff I have tested in WordPress, successfully.

    It's actually a better method because it uses a cookie when someone passes the age test that gives them access to the site, and since it's in the header, it checks for the cookie on every page load. In the earlier version, if someone had just gone directly to a page other than the home page, they wouldn't have faced an age check. This way, no one can access any part of the site without being old enough.

    This current code doesn't have your background image and styling included. I'd verify it works first before adding that in. Just to be safe.

    Fingers crossed!

  25. Finnaus
    Member
    Posted 1 year ago #

    Damn, I'm getting a syntax error on line 261 of the header (the last line of the header)
    and a syntax error on line 23 of the footer....By the way, I'm using the wordpress theme twentytwelve, I don't know if that matters or not.

    But here's the code in the header:

    <?php
    /**
     * The Header for our theme.
     *
     * Displays all of the <head> section and everything up till <div id="main">
     *
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
     */
    ?><!DOCTYPE html>
    <!--[if IE 7 | IE 8]>
    <html class="ie" <?php language_attributes(); ?>>
    <![endif]-->
    <!--[if !(IE 7) | !(IE 8)  ]><!-->
    <html <?php language_attributes(); ?>>
    <!--<![endif]-->
    <head>
    <meta charset="<?php bloginfo( 'charset' ); ?>" />
    <meta name="viewport" content="width=device-width" />
    <title><?php wp_title( '|', true, 'right' ); ?></title>
    <link rel="profile" href="http://gmpg.org/xfn/11" />
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
    <?php // Loads HTML5 JavaScript file to add support for HTML5 elements in older IE versions. ?>
    <!--[if lt IE 9]>
    <script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
    <![endif]-->
    <?php wp_head(); ?>
    </head>
    <?php if (!(isset($_COOKIE["AgeVerify"]))) { ?>
    <?php if($_POST['submitted'] != "") { ?>
    
    <?php 
    
    $minimumagetoviewsite = 21;
    $birthmonth = $_POST['month'];
    $birthdate = $_POST['date'];
    $birthyear = $_POST['year'];
    $todaysmonth = date("n");
    $todaysdate = date("j");
    $todaysyear = date("Y"); 
    
    if(($birthyear + $minimumagetoviewsite)<$todaysyear) {
    $yearcheck = "okay";
    } else if(($birthyear + $minimumagetoviewsite)>$todaysyear) {
    $yearcheck = "no";
    } else {
    $yearcheck = "same";
    }
    if($birthmonth < $todaysmonth) {
    $monthcheck = "okay";
    } else if($birthmonth > $todaysmonth) {
    $monthcheck = "no";
    } else {
    $monthcheck = "same";
    }
    if($birthdate <= $todaysdate) {
    $datecheck = "okay";
    } else {
    $datecheck = "no";
    };
    if ($yearcheck=="okay") {
    $agecheck = "pass";
    } else if ($yearcheck=="no") {
    $agecheck = "fail";
    } else {
    if ($monthcheck=="okay") {
    $agecheck = "pass";
    } else if ($monthcheck=="no") {
    $agecheck = "fail";
    } else {
    if ($datecheck=="okay") {
    $agecheck = "pass";
    } else if ($datecheck=="no") {
    $agecheck = "fail";
    }
    }
    }
    
    if($agecheck=="pass") { ?>
    
    <?php setcookie("AgeVerify", $value, time()+3600); ?>
    
    <?php } else { ?>
    
    This is where all the code goes for someone who's too young
    
    <?php }; ?>
    
    <?php } else { ?>
    <div style="position: absolute; bottom: 150px; right: 300px">
    <form method="post" action="">
    <select name="month">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    </select>
    <select name="date">
    <option>1</option>
    <option>2</option>
    <option>3</option>
    <option>4</option>
    <option>5</option>
    <option>6</option>
    <option>7</option>
    <option>8</option>
    <option>9</option>
    <option>10</option>
    <option>11</option>
    <option>12</option>
    <option>13</option>
    <option>14</option>
    <option>15</option>
    <option>16</option>
    <option>17</option>
    <option>18</option>
    <option>19</option>
    <option>20</option>
    <option>21</option>
    <option>22</option>
    <option>23</option>
    <option>24</option>
    <option>25</option>
    <option>26</option>
    <option>27</option>
    <option>28</option>
    <option>29</option>
    <option>30</option>
    <option>31</option>
    </select>
    <select name="year">
    <option>1920</option>
    <option>1921</option>
    <option>1922</option>
    <option>1923</option>
    <option>1924</option>
    <option>1925</option>
    <option>1926</option>
    <option>1927</option>
    <option>1928</option>
    <option>1929</option>
    <option>1930</option>
    <option>1931</option>
    <option>1932</option>
    <option>1933</option>
    <option>1934</option>
    <option>1935</option>
    <option>1936</option>
    <option>1937</option>
    <option>1938</option>
    <option>1939</option>
    <option>1940</option>
    <option>1941</option>
    <option>1942</option>
    <option>1943</option>
    <option>1944</option>
    <option>1945</option>
    <option>1946</option>
    <option>1947</option>
    <option>1948</option>
    <option>1949</option>
    <option>1950</option>
    <option>1951</option>
    <option>1952</option>
    <option>1953</option>
    <option>1954</option>
    <option>1955</option>
    <option>1956</option>
    <option>1957</option>
    <option>1958</option>
    <option>1959</option>
    <option>1960</option>
    <option>1961</option>
    <option>1962</option>
    <option>1963</option>
    <option>1964</option>
    <option>1965</option>
    <option>1966</option>
    <option>1967</option>
    <option>1968</option>
    <option>1969</option>
    <option>1970</option>
    <option>1971</option>
    <option>1972</option>
    <option>1973</option>
    <option>1974</option>
    <option>1975</option>
    <option>1976</option>
    <option>1977</option>
    <option>1978</option>
    <option>1979</option>
    <option>1980</option>
    <option>1981</option>
    <option>1982</option>
    <option>1983</option>
    <option>1984</option>
    <option>1985</option>
    <option>1986</option>
    <option>1987</option>
    <option>1988</option>
    <option>1989</option>
    <option>1990</option>
    <option>1991</option>
    <option>1992</option>
    <option>1993</option>
    <option>1994</option>
    <option>1995</option>
    <option>1996</option>
    <option>1997</option>
    <option>1998</option>
    <option>1999</option>
    <option>2000</option>
    <option>2001</option>
    <option>2002</option>
    <option>2003</option>
    <option>2004</option>
    <option>2005</option>
    <option>2006</option>
    <option>2007</option>
    <option>2008</option>
    <option>2009</option>
    <option>2010</option>
    <option>2011</option>
    <option>2012</option>
    </select>
    <input type="hidden" name="submitted" value="yes">
    <input type="submit" name="submit" value="verify">
    </form>
    </div>
    <?php }} else { ; ?>
    
    <body <?php body_class(); ?>>
    <div id="page" class="hfeed site">
    	<header id="masthead" class="site-header" role="banner">
    		<hgroup>
    			<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
    			<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
    		</hgroup>
    
    		<nav id="site-navigation" class="main-navigation" role="navigation">
    			<h3 class="menu-toggle"><?php _e( 'Menu', 'twentytwelve' ); ?></h3>
    			<div class="skip-link assistive-text"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentytwelve' ); ?>"><?php _e( 'Skip to content', 'twentytwelve' ); ?></a></div>
    			<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>
    		</nav><!-- #site-navigation -->
    
    		<?php $header_image = get_header_image();
    		if ( ! empty( $header_image ) ) : ?>
    			<a href="<?php echo esc_url( home_url( '/' ) ); ?>"><img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" /></a>
    		<?php endif; ?>
    	</header><!-- #masthead -->
    
    	<div id="main" class="wrapper">

    and here's the code for the footer:

    <?php
    /**
     * The template for displaying the footer.
     *
     * Contains footer content and the closing of the
     * #main and #page div elements.
     *
     * @package WordPress
     * @subpackage Twenty_Twelve
     * @since Twenty Twelve 1.0
     */
    ?>
    	</div><!-- #main .wrapper -->
    	<footer id="colophon" role="contentinfo">
    		<div class="site-info">
    			<?php do_action( 'twentytwelve_credits' ); ?>
    			<a href="<?php echo esc_url( __( 'http://wordpress.org/', 'twentytwelve' ) ); ?>" title="<?php esc_attr_e( 'Semantic Personal Publishing Platform', 'twentytwelve' ); ?>" rel="generator"><?php printf( __( 'Proudly powered by %s', 'twentytwelve' ), 'WordPress' ); ?></a>
    		</div><!-- .site-info -->
    	</footer><!-- #colophon -->
    </div><!-- #page -->
    
    <?php wp_footer(); ?>
    <?php }; ?>
    </body>
    </html>

    Thanks, again. If you can't find out what the problem is thats fine, I'll find another way!
    Thank you so much though, I'm really appreciating all the work you are doing for me :)

    -Finn

  26. Dandy Plow
    Member
    Posted 1 year ago #

    Yargh, I could kick myself for the error that I finally caught. The dropdown fields' assigned "names" are "month", "date", and "year". Names reserved by the core which you can't use. That was the culprit all along (as far as winding up with 'page not found' on submission).

    At any rate, I loaded up twentytwelve theme to make sure I got this working right.

    I couldn't get the cookies to stop conflicting with the header, so I switched to using session variables. So here's what you do.

    1. Go into the footer and remove <?php }; ?>

    2. Go into header and replace the entirety of the contents with this:

    <?php
        /**
         * The Header for our theme.
         *
         * Displays all of the <head> section and everything up till <div id="main">
         *
         * @package WordPress
         * @subpackage Twenty_Twelve
         * @since Twenty Twelve 1.0
         */
        ?>
    <!DOCTYPE html>
        <!--[if IE 7 | IE 8]>
        <html class="ie" <?php language_attributes(); ?>>
        <![endif]-->
        <!--[if !(IE 7) | !(IE 8)  ]><!-->
        <html <?php language_attributes(); ?>>
        <!--<![endif]-->
        <head>
        <meta charset="<?php bloginfo( 'charset' ); ?>" />
        <meta name="viewport" content="width=device-width" />
        <title><?php wp_title( '|', true, 'right' ); ?></title>
        <link rel="profile" href="http://gmpg.org/xfn/11" />
        <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>" />
        <?php // Loads HTML5 JavaScript file to add support for HTML5 elements in older IE versions. ?>
        <!--[if lt IE 9]>
        <script src="<?php echo get_template_directory_uri(); ?>/js/html5.js" type="text/javascript"></script>
        <![endif]-->
        <?php wp_head(); ?>
        </head>
        <body <?php body_class(); ?>>
    
        <?php if ($_SESSION['AgeVerify'] != "clear") {
        if($_POST['submitteds'] != "") {
        $minimumagetoviewsite = 21;
        $birthmonth = $_POST['monthofbirth'];
        $birthdate = $_POST['dateofbirth'];
        $birthyear = $_POST['yearofbirth'];
        $todaysmonth = date("n");
        $todaysdate = date("j");
        $todaysyear = date("Y");
        if(($birthyear + $minimumagetoviewsite)<$todaysyear) {
        $yearcheck = "okay";
        } else if(($birthyear + $minimumagetoviewsite)>$todaysyear) {
        $yearcheck = "no";
        } else {
        $yearcheck = "same";
        }
        if($birthmonth < $todaysmonth) {
        $monthcheck = "okay";
        } else if($birthmonth > $todaysmonth) {
        $monthcheck = "no";
        } else {
        $monthcheck = "same";
        }
        if($birthdate <= $todaysdate) {
        $datecheck = "okay";
        } else {
        $datecheck = "no";
        };
        if ($yearcheck=="okay") {
        $agecheck = "pass";
        } else if ($yearcheck=="no") {
        $agecheck = "fail";
        } else {
        if ($monthcheck=="okay") {
        $agecheck = "pass";
        } else if ($monthcheck=="no") {
        $agecheck = "fail";
        } else {
        if ($datecheck=="okay") {
        $agecheck = "pass";
        } else if ($datecheck=="no") {
        $agecheck = "fail";
        }
        }
        }
        if($agecheck=="pass") {
        $_SESSION['AgeVerify'] = "clear"; ?>
        <?php } else { ?>
        This is where all the code goes for someone who's too young
        <?php }; ?>
        <?php } else { ?>
        <div style="position: absolute; bottom: 150px; right: 300px">
        <form method="post" action="">
        <select name="monthofbirth">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
        <option>6</option>
        <option>7</option>
        <option>8</option>
        <option>9</option>
        <option>10</option>
        <option>11</option>
        <option>12</option>
        </select>
        <select name="dateofbirth">
        <option>1</option>
        <option>2</option>
        <option>3</option>
        <option>4</option>
        <option>5</option>
        <option>6</option>
        <option>7</option>
        <option>8</option>
        <option>9</option>
        <option>10</option>
        <option>11</option>
        <option>12</option>
        <option>13</option>
        <option>14</option>
        <option>15</option>
        <option>16</option>
        <option>17</option>
        <option>18</option>
        <option>19</option>
        <option>20</option>
        <option>21</option>
        <option>22</option>
        <option>23</option>
        <option>24</option>
        <option>25</option>
        <option>26</option>
        <option>27</option>
        <option>28</option>
        <option>29</option>
        <option>30</option>
        <option>31</option>
        </select>
        <select name="yearofbirth">
        <option>1920</option>
        <option>1921</option>
        <option>1922</option>
        <option>1923</option>
        <option>1924</option>
        <option>1925</option>
        <option>1926</option>
        <option>1927</option>
        <option>1928</option>
        <option>1929</option>
        <option>1930</option>
        <option>1931</option>
        <option>1932</option>
        <option>1933</option>
        <option>1934</option>
        <option>1935</option>
        <option>1936</option>
        <option>1937</option>
        <option>1938</option>
        <option>1939</option>
        <option>1940</option>
        <option>1941</option>
        <option>1942</option>
        <option>1943</option>
        <option>1944</option>
        <option>1945</option>
        <option>1946</option>
        <option>1947</option>
        <option>1948</option>
        <option>1949</option>
        <option>1950</option>
        <option>1951</option>
        <option>1952</option>
        <option>1953</option>
        <option>1954</option>
        <option>1955</option>
        <option>1956</option>
        <option>1957</option>
        <option>1958</option>
        <option>1959</option>
        <option>1960</option>
        <option>1961</option>
        <option>1962</option>
        <option>1963</option>
        <option>1964</option>
        <option>1965</option>
        <option>1966</option>
        <option>1967</option>
        <option>1968</option>
        <option>1969</option>
        <option>1970</option>
        <option>1971</option>
        <option>1972</option>
        <option>1973</option>
        <option>1974</option>
        <option>1975</option>
        <option>1976</option>
        <option>1977</option>
        <option>1978</option>
        <option>1979</option>
        <option>1980</option>
        <option>1981</option>
        <option>1982</option>
        <option>1983</option>
        <option>1984</option>
        <option>1985</option>
        <option>1986</option>
        <option>1987</option>
        <option>1988</option>
        <option>1989</option>
        <option>1990</option>
        <option>1991</option>
        <option>1992</option>
        <option>1993</option>
        <option>1994</option>
        <option>1995</option>
        <option>1996</option>
        <option>1997</option>
        <option>1998</option>
        <option>1999</option>
        <option>2000</option>
        <option>2001</option>
        <option>2002</option>
        <option>2003</option>
        <option>2004</option>
        <option>2005</option>
        <option>2006</option>
        <option>2007</option>
        <option>2008</option>
        <option>2009</option>
        <option>2010</option>
        <option>2011</option>
        <option>2012</option>
        </select>
        <input type="hidden" name="submitteds" value="yes">
        <input type="submit" name="verify" value="verify">
        </form>
        </div>
        <?php exit; }
    }; ?>
        <div id="page" class="hfeed site">
        	<header id="masthead" class="site-header" role="banner">
        		<hgroup>
        			<h1 class="site-title"><a href="<?php echo esc_url( home_url( '/' ) ); ?>" title="<?php echo esc_attr( get_bloginfo( 'name', 'display' ) ); ?>" rel="home"><?php bloginfo( 'name' ); ?></a></h1>
        			<h2 class="site-description"><?php bloginfo( 'description' ); ?></h2>
        		</hgroup>
    
        		<nav id="site-navigation" class="main-navigation" role="navigation">
        			<h3 class="menu-toggle"><?php _e( 'Menu', 'twentytwelve' ); ?></h3>
        			<div class="skip-link assistive-text"><a href="#content" title="<?php esc_attr_e( 'Skip to content', 'twentytwelve' ); ?>"><?php _e( 'Skip to content', 'twentytwelve' ); ?></a></div>
        			<?php wp_nav_menu( array( 'theme_location' => 'primary', 'menu_class' => 'nav-menu' ) ); ?>
        		</nav><!-- #site-navigation -->
    
        		<?php $header_image = get_header_image();
        		if ( ! empty( $header_image ) ) : ?>
        			<a href="<?php echo esc_url( home_url( '/' ) ); ?>"><img src="<?php echo esc_url( $header_image ); ?>" class="header-image" width="<?php echo get_custom_header()->width; ?>" height="<?php echo get_custom_header()->height; ?>" alt="" /></a>
        		<?php endif; ?>
        	</header><!-- #masthead -->
        	<div id="main" class="wrapper">

    3. Go into your ftp and open up wp-config.php. Right up at the top you'll see:

    * @package WordPress
     */
    
    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */

    Right in the little line gap in the middle, insert:

    session_start();

    making it:

    * @package WordPress
     */
    session_start();
    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
  27. Finnaus
    Member
    Posted 1 year ago #

    So it seems to be working!

    Just a couple things, that (I think) will be an easy fix.

    1. when I redirects to the main page, it's all in basic HTML.

    2. when you're not 21, it still just redirects you to the main page, is there a code I should put under `<?php } else { ?>
    This is where all the code goes for someone who's too young
    <?php }; ?>
    <?php } else { ?>`
    to redirect to a "to young" page or what?

    Thanks so much, I'm really glad it's working:D

    -Finn

  28. Finnaus
    Member
    Posted 1 year ago #

    Wait, I figured out the answer to my first question, I didn't have twenty twelve activated XD

    But my second question still stands.

  29. Finnaus
    Member
    Posted 1 year ago #

    And I answered my second question as well!

    Thank you so much Dandy! If you would like to see the final product of all of your amazing work, you can go to realmccoyspirits.com!

    Thank you so much!

    -Finn

  30. Dandy Plow
    Member
    Posted 1 year ago #

    Well done! Glad to help.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.