Web Design Forums

Welcome! Please register or log in: Forgot your password? Why register?
You are here: Web Design Forums » Programming Help » PHP » Age Verification Script RSS

Age Verification Script

This thread was started by Boogle and has been viewed 8456 times, and contains 27 replies, with the last reply made by DirtyDiyCode.
Page 1 of 2: 12 > Next Post Reply
1
124 points at 100% Repute
Boogle, WDF User Private message  
Posted August 19 '08 at 05:52 PM
      Posts: 61
Hello,

I need an age verification script, does anyone know where I could find one? I’ve seen quite a few free scripts around the internet but I’m unsure which is the best way of going about this. A good example of what I’m looking for can be found on (Edit by admin: link removed - please don't link to porn sites from here.) you porn .com. I need it to work exactly like this, just a simple warning then either “Enter” or “Exit”. I also need the session cookie part of the script to work the same.


I know some of these scripts require you to put the code before the PHP code on the index.php file. Some say it’s better to “include” on every other page. “include("include/verify.php")” I don’t know, what do you guys think?


Cheers
Last edited August 19 '08 at 08:11 PM by smoseley. Reply

Advertisement Register for free to hide these ads and participate in discussions!

2
837 points at 99% Repute WDFplus Member
Posted August 20 '08 at 04:02 AM
      Posts: 2,355
If all you need them to do is click Enter then how does this verify their age?

Either way, really it is just a glorified link, perhaps text or perhaps an image as the link.

Not sure what you mean by the session cookie, you want to create a cookie when they enter?

3
124 points at 100% Repute
Boogle, WDF User Private message  
Posted August 20 '08 at 03:31 PM
      Posts: 61
Some countries legally require a warning page if your website has adult material on it, particularly Germany, If you read YouPorn’s warning page is does stipulate that you should only enter if you are 18 or at least the age of majority in the jurisdiction where you reside. Having someone confirm how old they are by the user entering their D.O.B is totally pointless because obviously if you’re under age and looking for porn you’re going to lie. The reason for my warning page is to warn people who genuinely don’t want to see anything pornographic, so entering your age is irrelevant, and simple “Enter” or “Exit” will suffice.

I know I could just have a simple html file with “Enter” leading into the site and “Exit” leading to wherever. But, like I said I need some code that would put a cookie on the user’s computer so they would only have to verify once, or at least until they clean out their cookies.

All I need to know is what is the best way of going about this? Should I use PHP, Java Script or plain old html? More importantly, whichever of these options is the most efficient, could someone please point me in the right direction on how to implement it into my PHP script?

Thanks

4
837 points at 99% Repute WDFplus Member
Posted August 20 '08 at 03:46 PM
      Posts: 2,355
Okay, so you want to create a cookie and then to check to see if they are "verified".

This page http://www.w3schools.com/PHP/php_cookies.asp shows you how to create a cookie and check if a cookie exists.

5
1,325 points at 100% Repute WDFplus Member
Posted August 20 '08 at 06:03 PM
      Posts: 8,439
Here's what you need... a 2-script solution (one is an include, one is a verification page).

verify.php

<?php
session_start
();
if (
$_REQUEST["over18"] == 1) {
    
$_SESSION["over18"] = 1;
    
header("Location: " $_REQUEST["redirect"]);
}
?>
<html>
    <head>
        <title>Verify Your Age</title>
    </head>
    <body>
        <a href="verify.php?over18=1&redirect=<?=$redirect?>">I am over 18</a> | 
        <a href="http://www.google.com/">Get me out of here!</a>
    </body>
</html>


require_verification.php

<?php
session_start
();
if (
$_SESSION["over18"] != 1) {
    
header("Location: verify.php?redirect=" $PHP_SELF);
}
?>

content_page.php

(Make sure to include the require_verification as the first line of any containing pages to prevent header synchronization exceptions.)

<?php include("require_verification.php");  ?>
<html>
    <head>
        <title>Sensitive Content</title>
    </head>
    <body>
        <img src="something_sensitive.jpg" alt="EEK!!!" />
    </body>
</html>
</html>
Steven Moseley
President, Transio
Last edited August 20 '08 at 09:49 PM by smoseley. smoseley is online now! Reply

6
124 points at 100% Repute
Boogle, WDF User Private message  
Posted August 20 '08 at 07:34 PM
      Posts: 61
Thank you smoseley. I think the verify.php is best for me. I have a few questions though.

Where would I put the verify.php code? Do I put it into the index.php file or would it be on its own independent file? I don’t know how to configure this so it’s the first page a user would see.

I’m also wondering where I’ll have my css information for this page. All my other files on my website are tpl with links to the css info.

You’ll have to excuse my lack of knowledge on this subject, my php skills are still a work in progress.
Cheers

7
1,325 points at 100% Repute WDFplus Member
Posted August 20 '08 at 07:55 PM
      Posts: 8,439
You need all of the scripts for the system to work:
  1. verify.php is a stand-alone page, which is the verification page. You can add an html wrapper for it to make it look pretty.

  2. require_verification.php is an include that you put in pages that require age verification. it will redirect the user to verify.php if they haven't already verified their age.

  3. content_page.php is an example of how you include the require_verification.php script into any page requiring verification.
Steven Moseley
President, Transio
Last edited August 20 '08 at 07:55 PM by smoseley. smoseley is online now! Reply

8
124 points at 100% Repute
Boogle, WDF User Private message  
Posted August 20 '08 at 08:53 PM
      Posts: 61
Yeah, I’ve got! It all makes sense now.

Will it remember that the user as verified their age? I only want the include in the index.php, every page on the website has adult material on it so once someone as verified their age will it make them do it again if they click on the “Home” button on my site - the “Home” button links to the index.php file. That’s why I mentioned cookies in my post, can I implement some sort of “session cookie” that would remember, so the user only verifies once.

Cheers

9
1,325 points at 100% Repute WDFplus Member
Posted August 20 '08 at 09:48 PM
      Posts: 8,439
The age verification will be remembered for the browser session (until the next time they visit the site). This is the proper way to do it.

Include the verification script on every page that will contain sensitive content.
Steven Moseley
President, Transio
smoseley is online now! Reply

10
1,325 points at 100% Repute WDFplus Member
Posted August 20 '08 at 09:49 PM
      Posts: 8,439
By the way... I made a necessary update to the script. Use the latest version above.
Steven Moseley
President, Transio
smoseley is online now! Reply

11
124 points at 100% Repute
Boogle, WDF User Private message  
Posted August 20 '08 at 10:18 PM
      Posts: 61
Ok. I’ll put this code on every page that contains adult material, not just the index.php.

So just to clarify, the require_verification.php is a stone-alone page too right? I just put this in my “include” folder which is in the “public_html” folder (that’s where all the other include files are anyway). And I’m guessing I’ll put the verify.php page with all the other php files. All I need do then is put this bit of code: include("include/require_verification.php"); into all the pages that need verifying.

Cheers smoseley, I appreciate your help.

12
124 points at 100% Repute
Boogle, WDF User Private message  
Posted August 20 '08 at 10:38 PM
      Posts: 61
I’ve just realised something. Which section do I edit to make the script go into my website?

Is it in the verify.php. I just change this:

<a href="verify.php?over18=1&redirect=<?=$redirect?>">I am over 18</a>


To this
<a href="index.php?over18=1&redirect=<?=$redirect?>">I am over 18</a>


Thanks for your patience

Cheers

13
1,325 points at 100% Repute WDFplus Member
Posted August 21 '08 at 11:58 AM
      Posts: 8,439
You don't need to edit anything. The script will automatically redirect to the page that requires verification. It's "smart".
Steven Moseley
President, Transio
Last edited August 21 '08 at 11:59 AM by smoseley. smoseley is online now! Reply

14
124 points at 100% Repute
Boogle, WDF User Private message  
Posted August 22 '08 at 07:22 PM
      Posts: 61
Hi,

Script works great in IE7 but I’m having no luck with Fire Fox (2.0.0.16). I’ve not tried the other browsers like Safari or Opera but I’m guessing they’re the same. The verify.php file displays ok it just doesn’t take you into the site when you press enter, it stays on the verify page. In IE it’s 100% ok, works exactly how it should.

Cheers

15
1,325 points at 100% Repute WDFplus Member
Posted August 22 '08 at 07:55 PM
      Posts: 8,439
It works for me in firefox...

Go here first, requires authentication.
http://www.transio.com/age_verification/content1.php

After authenticating, it redirects you back to the page.

Then, if you go to a second page requiring authentication, you're already good.
http://www.transio.com/age_verification/content2.php

But close your browser and reopen it and you'll have to authenticate again.
Steven Moseley
President, Transio
smoseley is online now! Reply

16
124 points at 100% Repute
Boogle, WDF User Private message  
Posted August 22 '08 at 09:26 PM
      Posts: 61
It works for me in firefox...

Go here first, requires authentication.
http://www.transio.com/age_verification/content1.php

After authenticating, it redirects you back to the page.

Then, if you go to a second page requiring authentication, you're already good.
http://www.transio.com/age_verification/content2.php

But close your browser and reopen it and you'll have to authenticate again.



This works for me too. Must be something in my script or on my server... I'll take a closer look.

Cheers

17
1,325 points at 100% Repute WDFplus Member
Posted August 23 '08 at 11:26 AM
      Posts: 8,439
Ok, I think I found the problem.

Try this in verify.php:

change this:

<a href="verify.php?over18=1&redirect=<?=$redirect?>">

to this:

<a href="verify.php?over18=1&redirect=<?php echo $_REQUEST["redirect"]; ?>">

Let me know if that works.
Steven Moseley
President, Transio
Last edited August 23 '08 at 11:26 AM by smoseley. smoseley is online now! Reply

18
124 points at 100% Repute
Boogle, WDF User Private message  
Posted August 24 '08 at 03:51 AM
      Posts: 61
Ok, I think I found the problem.

Try this in verify.php:

change this:

<a href="verify.php?over18=1&redirect=<?=$redirect?>">

to this:

<a href="verify.php?over18=1&redirect=<?php echo $_REQUEST["redirect"]; ?>">
Let me know if that works.

Still not working unfortunately.



19
1,325 points at 100% Repute WDFplus Member
Posted August 24 '08 at 09:19 AM
      Posts: 8,439
ok, change require_verification.php to the following:

<?php
session_start
();
if (
$_SESSION["over18"] != 1) {
    
header("Location: verify.php?redirect=" $_SERVER["SCRIPT_NAME"]);
}
?>

If that doesn't work, I'm lost.
Steven Moseley
President, Transio
smoseley is online now! Reply

20
124 points at 100% Repute
Boogle, WDF User Private message  
Posted August 24 '08 at 12:33 PM
      Posts: 61
ok, change require_verification.php to the following:

<?php
session_start
();
if (
$_SESSION["over18"] != 1) {
    
header("Location: verify.php?redirect=" $_SERVER["SCRIPT_NAME"]);
}
?>

If that doesn't work, I'm lost.
Sorry, no joy.

I’ll get my programmer to take a look. Thanks for trying smoseley, the script is great, must be something with my script or even my server.

Cheers

21
1,325 points at 100% Repute WDFplus Member
Posted August 24 '08 at 01:39 PM
      Posts: 8,439
That was what I was thinking is that it could be a server configuration issue. It seems like the require_verification script isn't getting the current page data. Do you know what version of PHP you're using?
Steven Moseley
President, Transio
smoseley is online now! Reply

22
124 points at 100% Repute
Boogle, WDF User Private message  
Posted August 24 '08 at 07:27 PM
      Posts: 61
That was what I was thinking is that it could be a server configuration issue. It seems like the require_verification script isn't getting the current page data. Do you know what version of PHP you're using?

I think it's php 5.

23
1,325 points at 100% Repute WDFplus Member
Posted August 24 '08 at 07:41 PM
      Posts: 8,439
Looked at your phpinfo... everything there looks fine. I have no clue why it's not working.
Steven Moseley
President, Transio
smoseley is online now! Reply

24
1,325 points at 100% Repute WDFplus Member
Posted August 24 '08 at 07:42 PM
      Posts: 8,439
Do me a favor, post the source of the "termsofuse.php" page.
Steven Moseley
President, Transio
smoseley is online now! Reply

25
View sugarfree's reputation
sugarfree, WDF Noob Private message  
Posted April 18 '09 at 10:18 PM
      Posts: 1
I'm attempting to implement the script posted above, but the problem I am having is that it seems to require verification every couple pages or so. So once a user verifies their age, once they've browsed a couple pages it will kick them back to the age verification age where they must verify their age again.

I'm not sure why it is happening and I was hoping someone might have some helpful thoughts?

Page 1 of 2: 12 > Next Post Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP backup script xarst Coding Articles & Tutorials 6 May 7 '07 08:40 AM
Automatic break-out-of-frames Java Script with no hype in code... kristof Javascript, AJAX, and JSON 19 April 22 '06 05:33 AM
Verification script rinkrat Questions Before I Buy 1 July 4 '05 12:15 PM
Need a quick modification made to an ASP(.net?) script.... screenweb ASP and .NET 2 August 9 '04 01:52 PM