Simple PHP Script That Checks User’s Age and Restricts or Grants Access to Restricted Content A PHP tutorial/download

Building on a script covered in a recent tutorial, Simple PHP Script That Accurately Determines User’s Age (in Years), I’ve updated the second variation of the script to not only determine the user’s age but to also determine whether the user is old enough to see certain content.

The front end still looks the same, like this, minus the top message:

A simple age input PHP script
A simple PHP script that takes the user’s birthdate input and accurately outputs their age (in years.)

Instead of outputting a message, the script will redirect you to either a pre-existing webpage of your choice or to a template in which you can provide the content you’re age-restricting. You can see the new code added to the script below:

The variable section
In this section, you can set the minimum age ($minage), the method you want to use to serve the content to the user who is old enough to see it, and then the url for the pre-existing page if you use method #1.

To be clear, there are two methods. The first one allows you to redirect to a pre-existing page of your choice and the second method is hard-coded to redirect the user to the custom.php page included with the script.

// Edit these variables only!

// Important! Make sure to set the following variable to the age in which the user must be to be approved to see content
$minage = "13";

// The method following approval (if user is old enough) -- 1 = redirect to a pre-existing page/url, 2 = custom code which can be updated in custom.php template
$method = "2";

// method 1 -- if you choose to redirect to another page, set the url in the variable below
$url = "http://kimenders.com"; 
// method 2 -- a reminder -- If you selected 2 as your method, you will need to customize the content template file included with this script

// End of variables section

The other two chunks of code that were added depend on whether the user:
1) has already had their birthday this year (due to the current month being past the birth month)
2) hasn’t had their birthday yet and the current month is their birth month
3) has had their birthday and it is still their current birth month
4) hasn’t had their birthday yet and it isn’t their birth month yet

Chunk for if their birthday has occurred:

                  if($user_age >= $minage) {
                  
                       if($method == '1') {
                       
                       header('Location: '.$url);

                       } elseif($method == '2') {

                       header("Location: custom.php");

                       }

                  } else {

                  echo "Sorry. You are not old enough to view this content.";

                  } 

Chunk for if their birthday hasn’t occurred:

 
                                 if($adjusted_user_age >= $minage) {
                                  
                                 if($method == '1') {
                       
                                 header('Location: '.$url);

                                 } elseif($method == '2') {
     
                                 header("Location: custom.php");

                                 }

                                 } else {

                                 echo "Sorry. You are not old enough to view this content.";

                                 }  

As you can see, the chunks of code are very nearly identical — the only difference coming down to the user_age variable.

This script, just like its preceding version is still quite bare and basic. It can certainly be dressed up with CSS and integrated into an existing site easily. If you’re looking for a simple php script that you can integrate into your site that restricts a user if they’re not old enough to access content, then this would fit that bill.

To download it, click the link below!

If you found this post useful, leave a comment below!

52 comments

  1. Процесс верификации даёт клиенту казино ряд дополнительных привилегий, например, дарятся пинкоины (внутренняя валюта клуба), которые можно копить и расти по статусу.

  2. Shirley Kwok says:

    Главное условие для пользователей онлайн казино Вулкан Россия – создание аккаунта для посетителей не младше 18 лет.

  3. First of all I would like to say great blog! I had a quick question in which I’d like to ask if you do not mind. I was curious to know how you center yourself and clear your thoughts prior to writing. I have had difficulty clearing my thoughts in getting my ideas out. I truly do enjoy writing but it just seems like the first 10 to 15 minutes are generally lost simply just trying to figure out how to begin. Any recommendations or tips? Cheers!

  4. Iesha Cruse says:

    Everything composed made a ton of sense. But, think on this, what if you were to write a awesome headline? I ain’t saying your content is not good, however what if you added something that grabbed a person’s attention? I mean Simple PHP Script That Checks User’s Age and Restricts or Grants Access to Restricted Content A PHP tutorial/download is a little boring. You ought to peek at Yahoo’s home page and watch how they create post headlines to grab people to open the links. You might add a related video or a picture or two to grab people interested about what you’ve got to say. Just my opinion, it might bring your website a little bit more interesting.

  5. I have been exploring for a bit for any high-quality articles or weblog posts on this sort of space . Exploring in Yahoo I at last stumbled upon this website. Studying this info So i’m glad to express that I have a very excellent uncanny feeling I found out just what I needed. I such a lot surely will make sure to do not fail to remember this website and give it a glance on a constant basis.

  6. Alexis Fetty says:

    Hello,
    What an nice article!
    May I scrape this and share this with my community members?
    My group is about Korean 야동
    If ever you are interested, feel free to visit my channel and have a look.
    Thanks and Keep up the good work!

  7. Great goods from you, man. I’ve understand your stuff previous to and you’re just extremely fantastic. I actually like what you have acquired here, really like what you’re saying and the way in which you say it. You make it enjoyable and you still care for to keep it sensible. I can not wait to read much more from you. This is actually a wonderful website.

  8. Whether your home has suffered catastrophic roof damage, a slow water leak or anything in-between, you can count on us for fast and professional restoration so you can get back to what matters most.

  9. Retha Godley says:

    Наш каталог финансовых продуктов — это ваш универсальный ресурс для сравнения и выбора различных финансовых продуктов от ведущих поставщиков.
    взять займ Независимо от того, ищете ли вы высокодоходные сберегательные счета, инвестиционные фонды с низкой комиссией или персонализированные консультации по финансовому планированию,
    виртуальная кредитная карта у нас есть все необходимое, чтобы помочь вам достичь ваших финансовых целей.

  10. To absolutely harness the potential of UK Teatime Results, one needs to go beyond fundamental number tracking and take part in a sophisticated analysis of historic information, discovering patterns via analytical tools like suggest and common.

  11. I write a comment each time I especially enjoy a article on a site or if I have something to contribute to the conversation. It is caused by the fire communicated in the post I browsed. And on this article Simple PHP Script That Checks User’s Age and Restricts or Grants Access to Restricted Content A PHP tutorial/download. I was moved enough to drop a thought 🙂 I actually do have some questions for you if it’s allright. Could it be just me or does it seem like some of the responses come across like left by brain dead people? 😛 And, if you are writing on additional sites, I’d like to keep up with you. Could you make a list all of all your shared pages like your twitter feed, Facebook page or linkedin profile?

  12. Niklas Stone says:

    I don’t drop a lot of remarks, but after reading some of the responses here Is On The Web Ripe For Embezzlement?. I do have some questions for you if it’s allright. Could it be just me or do a few of these comments come across like they are written by brain dead visitors? 😛 And, if you are writing on additional places, I’d like to keep up with anything fresh you have to post. Could you list of the complete urls of your shared sites like your linkedin profile, Facebook page or twitter feed?

  13. Ronda Ievers says:

    You could certainly see your expertise within the article you write. The arena hopes for even more passionate writers like you who are not afraid to mention how they believe. Always follow your heart.

  14. Arlene Horne says:

    Hello there, You have done an incredible job. I’ll definitely digg it and personally suggest to my friends. I am confident they will be benefited from this website.

  15. Jaxon Ritter says:

    Behavior SupportThe Behavior Support Team works with teachers and families to support children in their social emotional development and assists with any behavioral issues that may be impacting their school readiness.

  16. Thanks for finally talking about >Simple PHP Script That Checks User’s Age and Restricts or Grants Access to Restricted Content A PHP tutorial/download <Loved it!

  17. I do not even know how I ended up here, however I thought this publish was great. I do not realize who you’re however certainly you’re going to a famous blogger should you are not already. Cheers!

  18. Usually I don’t read post on blogs, but I would like to say that this write-up very compelled me to check out and do it! Your writing style has been surprised me. Thanks, quite great article.

  19. This is very attention-grabbing, You’re an overly skilled blogger. I have joined your rss feed and stay up for looking for more of your magnificent post. Additionally, I’ve shared your web site in my social networks

Leave a Reply

Your email address will not be published. Required fields are marked *