944,180 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 15625
  • PHP RSS
Apr 10th, 2007
0

Age Verification Script

Expand Post »
Duke SNIPPED Nukem will only allow 18 and above on his site. It seems like my html page is correct and my php is the problem. Anyone have any answers they would like to share with me? MAY JUSTICE REIGN SUPREME!!!!!





PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $month = $_REQUEST['bmonth'];
  3. $day = $_REQUEST['day'];
  4. $year = $_REQUEST['year'];
  5. $this_day = date(d);
  6. $this_month = date(m);
  7. $this_year = date(Y);
  8. $day_val = $this_day - $day;
  9. $month_val = $this_month - $month;
  10. $year_val = $this_year - $year;
  11. if($year_val >= 19) {
  12. header('Location: <a rel="nofollow" href="http://www.URL.com/Tour/Tour1.html'" target="_blank">http://www.URL.com/Tour/Tour1.html'</a>);
  13. }
  14. if($month_val >= 0) {
  15. header('Location: <a rel="nofollow" href="http://www.URL.com/Tour/Tour1.html'" target="_blank">http://www.URL.com/Tour/Tour1.html'</a>);
  16. }
  17. if($day_val >= 0) {
  18. header('Location: <a rel="nofollow" href="http://www.URL.com/Tour/Tour1.html'" target="_blank">http://www.URL.com/Tour/Tour1.html'</a>);
  19.  
  20. } else {
  21. header('Location: <a rel="nofollow" href="http://www.URL.com/notvalidbday.html'" target="_blank">http://www.URL.com/notvalidbday.html'</a>);
  22. }
  23. ?>




Last edited by happygeek; Aug 2nd, 2009 at 2:42 pm. Reason: removed vulgarities, snipped adult url
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Duke Nukem is offline Offline
2 posts
since Apr 2007
Apr 10th, 2007
0

Re: Age Verification Script

dude you should remove the three conditions and put em in one condition so the code should look something like this

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $month = $_REQUEST['bmonth'];
  3. $day = $_REQUEST['day'];
  4. $year = $_REQUEST['year'];
  5. $this_day = date(d);
  6. $this_month = date(m);
  7. $this_year = date(Y);
  8. $day_val = $this_day - $day;
  9. $month_val = $this_month - $month;
  10. $year_val = $this_year - $year;
  11. if($year_val >= 19&&$month_val >= 0&&$day_val >= 0) {
  12. header('Location: http://www.URL.com/Tour/Tour1.html');
  13. }
  14. else {
  15. header('Location: http://www.URL.com/notvalidbday.html');
  16. }
  17.  
  18. ?>
Last edited by happygeek; Aug 2nd, 2009 at 2:42 pm. Reason: snipped adult URLs in code
Reputation Points: 18
Solved Threads: 9
Junior Poster
w_3rabi is offline Offline
160 posts
since Dec 2006
Apr 11th, 2007
0

Re: Age Verification Script

Nice!!! Thanks for the help!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Duke Nukem is offline Offline
2 posts
since Apr 2007
Apr 11th, 2007
0

Re: Age Verification Script

no problem man
take care
Reputation Points: 18
Solved Threads: 9
Junior Poster
w_3rabi is offline Offline
160 posts
since Dec 2006
Aug 2nd, 2009
0

Re: Age Verification Script

This script doesn't work! Calculation is off beat
Reputation Points: 10
Solved Threads: 0
Newbie Poster
14music is offline Offline
2 posts
since Aug 2009
Aug 2nd, 2009
0

Re: Age Verification Script

try this one
php Syntax (Toggle Plain Text)
  1. <?php
  2. $allowed_age = 19;
  3. $bdate = strtotime($_REQUEST['y'].'-'.$_REQUEST['m']."-".$_REQUEST['d']);
  4. $age = (time()-$bdate)/31536000;
  5. if($age >= $allowed_age) {
  6. header('Location: http://www.URL.com/Tour/Tour1.html');
  7. exit;
  8. }
  9. else {
  10. header('Location: http://www.URL.com/notvalidbday.html');
  11. exit;
  12. }
  13. ?>
Last edited by happygeek; Aug 2nd, 2009 at 2:43 pm. Reason: Snipped adult URL in code
Reputation Points: 18
Solved Threads: 9
Junior Poster
w_3rabi is offline Offline
160 posts
since Dec 2006
Aug 2nd, 2009
0

Re: Age Verification Script

Redirect problem
Reputation Points: 10
Solved Threads: 0
Newbie Poster
14music is offline Offline
2 posts
since Aug 2009
Feb 18th, 2010
0

What about set and check cookie?

Click to Expand / Collapse  Quote originally posted by w_3rabi ...
try this one
php Syntax (Toggle Plain Text)
  1. <?php
  2. $allowed_age = 19;
  3. $bdate = strtotime($_REQUEST['y'].'-'.$_REQUEST['m']."-".$_REQUEST['d']);
  4. $age = (time()-$bdate)/31536000;
  5. if($age >= $allowed_age) {
  6. header('Location: http://www.URL.com/Tour/Tour1.html');
  7. exit;
  8. }
  9. else {
  10. header('Location: http://www.URL.com/notvalidbday.html');
  11. exit;
  12. }
  13. ?>
This works fine. Thanks. I was trying to add set cookie to expand on this, which works, but resets the cookie value each time. I want to check if someone has already entered their age and if so, direct them to the appropriate response page. i.e. - don't want a youth hitting back button and enter different age. I know this is easily circumvented anyways, but ESRB requires it for adult game trailers, etc. Here is what I have so far -

PHP Syntax (Toggle Plain Text)
  1. <?php
  2. $allowed_age = 18;
  3. $bdate = strtotime($_REQUEST['year'].'-'.$_REQUEST['month']."-".$_REQUEST['day']);
  4. $age = (time()-$bdate)/31536000;
  5. if($age >= $allowed_age) {
  6. setcookie('legal', 'yes', time() + 31556926, '/', '.'.$_SERVER['SERVER_NAME']);
  7. header('Location: http://www.myserver.com/adult.html');
  8. exit;
  9. }
  10. else {
  11. setcookie('legal', 'no', time() + 31556926, '/', '.'.$_SERVER['SERVER_NAME']);
  12. header('Location: http://www.myserver.com/minor.html');
  13. exit;
  14. }
  15. ?>

Here is what the cookie looks like if I retrieve it -
for minor:
noArray ( [0379923826258bc7cbcfa89cd386917d] => e33f27206e07981d495d11f70581e790 [29e6895b11c34b79d161fe2a6f1702f0] => b7b4ff91eb8090ad2f85d6a2100d3c4e [legal] => no )

for adult:
yesArray ( [0379923826258bc7cbcfa89cd386917d] => e33f27206e07981d495d11f70581e790 [29e6895b11c34b79d161fe2a6f1702f0] => b7b4ff91eb8090ad2f85d6a2100d3c4e [legal] => yes )

Thanks for any help in advance!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tkemp is offline Offline
2 posts
since Feb 2010
Oct 10th, 2010
0
Re: Age Verification Script
I would do something like this:

PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. function allowed( $y, $m, $d, $min ) {
  4. $age = date("Y") - $y - (( date("md") < $m.$d ) ? 1 : 0);
  5. return ( $age >= $min ) ? true : false;
  6. }
  7.  
  8. if ( allowed($_REQUEST['year'], $_REQUEST['bmonth'], $_REQUEST['day'], 18) )
  9. {
  10. header('Location: http://www.URL.com/Tour/Tour1.html');
  11. }
  12. else
  13. {
  14. header('Location: http://www.URL.com/notvalidbday.html');
  15. }
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Ghostt0 is offline Offline
24 posts
since Jul 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: system() or exec() not working properly
Next Thread in PHP Forum Timeline: Best userpofile script or something?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC