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:
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!
I have read so many content regarding the blogger lovers however this paragraph is genuinely a pleasant paragraph, keep it up.
There is definately a great deal to learn about this subject. I like all of the points you have made.
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!
It prepares and files documentation, appears before government agencies, and provides ongoing counsel throughout visa, naturalization, citizenship, and asylum cases.
Wow, that’s what I was exploring for, what a information! present here at this web site, thanks admin of this website.
What’s up, after reading this awesome paragraph i am also delighted to share my knowledge here with mates.
It’s amazing designed for me to have a web site, which is good designed for my know-how. thanks admin
What’s up friends, how is the whole thing, and what you want to say concerning this piece of writing, in my view its genuinely remarkable in support of me.
Magnificent web site. A lot of helpful information here. I’m sending it to several buddies ans additionally sharing in delicious. And obviously, thank you on your effort!
What’s up friends, its enormous piece of writing on the topic of tutoringand fully explained, keep it up all the time.
These emit super-bright dive lights when fishing, hiking, camping, trekking, or emergencies.
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!
At this time I am ready to do my breakfast, when having my breakfast coming over again to read more news.
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.
This excellent website really has all of the information I wanted concerning this subject and didn’t know who to ask.
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