Jump to content

[SOLVED] restricting age to minimum 18 years in registration


Recommended Posts

it is possible, if I were you i will change Validate.php class (classes/Validate.php)

 

there is a function which checking birthdate format:  public static function isBirthDate($date)

 

add there if condition to check age:
 

if (date('Y')-$birth_date[1]<=18)
    return false;  

final code of isBirtDate function:

	public static function isBirthDate($date)
	{
		if (empty($date) || $date == '0000-00-00')
			return false;
		if (preg_match('/^([0-9]{4})-((?:0?[1-9])|(?:1[0-2]))-((?:0?[1-9])|(?:[1-2][0-9])|(?:3[01]))([0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date, $birth_date))
		{
		    if (date('Y')-$birth_date[1]<=18)
		        return false;  
			if ($birth_date[1] > date('Y') && $birth_date[2] > date('m') && $birth_date[3] > date('d'))
				return false;
			return true;
		}
		return false;
	}

voila :)

  • Like 3
Link to comment
Share on other sites

that's correct, but in some countries you have to block possibility to "watch" or "order" adult contents.

May i know where you live?

here, in europe, in several countries we have really weirdy law in some cases (like cookies notification: LOL)

Link to comment
Share on other sites

  • 5 months later...

it is possible, if I were you i will change Validate.php class (classes/Validate.php)

 

there is a function which checking birthdate format:  public static function isBirthDate($date)

 

add there if condition to check age:

 

if (date('Y')-$birth_date[1]<=18)
    return false;  

final code of isBirtDate function:

	public static function isBirthDate($date)
	{
		if (empty($date) || $date == '0000-00-00')
			return false;
		if (preg_match('/^([0-9]{4})-((?:0?[1-9])|(?:1[0-2]))-((?:0?[1-9])|(?:[1-2][0-9])|(?:3[01]))([0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date, $birth_date))
		{
		    if (date('Y')-$birth_date[1]<=18)
		        return false;  
			if ($birth_date[1] > date('Y') && $birth_date[2] > date('m') && $birth_date[3] > date('d'))
				return false;
			return true;
		}
		return false;
	}

voila :)

 

hi vekia

 

this condition is not really accurate.

We are now for example in 2014 and let say some1 turned 18 last or any oder day this year. the condition wont work. It is now taking into account only customers that have been born until 31 - Dec - 1995

Link to comment
Share on other sites

hi vekia

 

this condition is not really accurate.

We are now for example in 2014 and let say some1 turned 18 last or any oder day this year. the condition wont work. It is now taking into account only customers that have been born until 31 - Dec - 1995

the conndition must be written according to entire date not only year

 

if (date('Y')-$birth_date[1]<=18)

Link to comment
Share on other sites

the right code for this seems to be this one 

public static function isBirthDate($date)
{
if (empty($date) || $date == '0000-00-00')
return false;
if (preg_match('/^([0-9]{4})-((?:0?[1-9])|(?:1[0-2]))-((?:0?[1-9])|(?:[1-2][0-9])|(?:3[01]))([0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date, $birth_date))
{
   if ((floor((time() - strtotime($date))/31556926))<18)
       return false;  
if ($birth_date[1] > date('Y') && $birth_date[2] > date('m') && $birth_date[3] > date('d'))
return false;
return true;
}
return false;
}

i have tested and it works

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 1 month later...

the right code for this seems to be this one 

public static function isBirthDate($date)
{
if (empty($date) || $date == '0000-00-00')
return false;
if (preg_match('/^([0-9]{4})-((?:0?[1-9])|(?:1[0-2]))-((?:0?[1-9])|(?:[1-2][0-9])|(?:3[01]))([0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date, $birth_date))
{
   if ((floor((time() - strtotime($date))/31556926))<18)
       return false;  
if ($birth_date[1] > date('Y') && $birth_date[2] > date('m') && $birth_date[3] > date('d'))
return false;
return true;
}
return false;
}

i have tested and it works

 

Thank you, works perfectly. Only need to change the error message log(if you are not 18 years old), but that's no problem.

Link to comment
Share on other sites

  • 4 weeks later...
  • 2 months later...

Thank you, works perfectly. Only need to change the error message log(if you are not 18 years old), but that's no problem.

 

Hi,

 

Could you please explain how do you change the error message log only if the user isn't 18 years old ?

 

Thank you

Link to comment
Share on other sites

For example, if an user isn't 18 years old and try to create an account, the error message says "you aren't 18 years old".

ve a tu pagina/translations/es o en/errors.php y busca la linea 736 donde dice Fecha de nacimiento inválida
cambialo por Debe tener 18 años de Edad para poder Registrarte en nuestra Tienda o algo asi. cierra guardas los cambios y listo
lo hice asi y me funciona de maravilla claro con el codigo que ustedes me dieron.
 
IF YOU WANT TO LOOK AT THE PAGE THAT I TEST AND TRY TO REGISTER WITH A DATE TO BE MINOR AND WATCH THE NOTICE GOES www.nino.hol.es
Edited by paez903 (see edit history)
Link to comment
Share on other sites

For example, if an user isn't 18 years old and try to create an account, the error message says "you aren't 18 years old".

 

so, you followed guidelines that i mentioned severa posts before?

an answer for your question is there

just follow guidelines, apply code that i suggested to use (and sooroos) and it will work

 

ve a tu pagina/translations/es o en/errors.php y busca la linea 736 donde dice Fecha de nacimiento inválida
cambialo por Debe tener 18 años de Edad para poder Registrarte en nuestra Tienda o algo asi. cierra guardas los cambios y listo
lo hice asi y me funciona de maravilla claro con el codigo que ustedes me dieron.

 

 

i don't understand :(

please in english here

Link to comment
Share on other sites

sorry was not my intention, first of all go to your website via FTP, and seeks the following address: name of your page / translations / en / errors.php and Find the line where it says 736 invalid Birthdate 

By change it must be 18 years of age to check in our store or message you want it to say. Guard changes and ready. 

 

I did it that way and it works to perfection and use the story to the code that provided in this topic.

 

IF YOU WANT TO LOOK AT THE PAGE THAT I TEST AND TRY TO REGISTER WITH A DATE TO BE MINOR AND WATCH THE NOTICE GOES        www.nino.hol.es

Edited by paez903 (see edit history)
Link to comment
Share on other sites

so, you followed guidelines that i mentioned severa posts before?

an answer for your question is there

just follow guidelines, apply code that i suggested to use (and sooroos) and it will work

 

i don't understand :(

please in english here

sorry was not my intention, first of all go to your website via FTP, and seeks the following address: name of your page / translations / en / errors.php and Find the line where it says 736 invalid Birthdate 
By change it must be 18 years of age to check in our store or message you want it to say. Guard changes and ready. 
 
I did it that way and it works to perfection and use the story to the code that provided in this topic.
Link to comment
Share on other sites

  • 2 months later...

Hi can you tell me if this Validate.php has to be edited with Notepad++ only or it can be edited with regular notepad also?

 

better to edit with notepad++ because it will handle proper coding of file.

in some cases simple notepad can change the file encoding and you will have little troubles with BOM (weirdy chars at the begining of the file). it can affect many things.

Link to comment
Share on other sites

better to edit with notepad++ because it will handle proper coding of file.

in some cases simple notepad can change the file encoding and you will have little troubles with BOM (weirdy chars at the begining of the file). it can affect many things.

Thank you, yes i think i recently had troubles when editing with just notepad so i had to restore the language to fix it.

 

So in order to set limitation to age on my website i just have to edit validate.php file the way you wrote on the begining of this thread right?

Link to comment
Share on other sites

  • 5 weeks later...

 

you can do it with code like:

if (Validate::isBirthDate($date)==false) {
echo "you aren't 18 years old";
}

 

Hi :)

 

I tried to place that code on several places in Validate.php but I got an error each time.

 

Can you give me the full piece of code master Vekia ?

  • Like 1
Link to comment
Share on other sites

  • 2 weeks later...
  • 4 months later...
  • 1 year later...

Sorry to revive old topic. I use PS 1.6 and it worked for me.

 

Just want to say Thank you !

 

 

it is possible, if I were you i will change Validate.php class (classes/Validate.php)

 

there is a function which checking birthdate format:  public static function isBirthDate($date)

 

add there if condition to check age:
 

if (date('Y')-$birth_date[1]<=18)
    return false;  

final code of isBirtDate function:

	public static function isBirthDate($date)
	{
		if (empty($date) || $date == '0000-00-00')
			return false;
		if (preg_match('/^([0-9]{4})-((?:0?[1-9])|(?:1[0-2]))-((?:0?[1-9])|(?:[1-2][0-9])|(?:3[01]))([0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $date, $birth_date))
		{
		    if (date('Y')-$birth_date[1]<=18)
		        return false;  
			if ($birth_date[1] > date('Y') && $birth_date[2] > date('m') && $birth_date[3] > date('d'))
				return false;
			return true;
		}
		return false;
	}

voila :)

Link to comment
Share on other sites

×
×
  • Create New...