Hi everyone, I have a website and need a age verification so young kids can't visit my website. I have a code and works well but it's constantly asking age verification in any page I visit my website. Can anyone help me on how to configure this code so it only ask once for age verification, thanks in advance.

    <script type="text/javascript">// <![CDATA[
    var agePrompt=prompt("What is your age?");

    if (agePrompt>=18) alert('Welcome!')
    else {
    alert('Sorry! Come back in a few years!')
    document.location="https://www.1adslinks.com/MISC/adult";

    }
    // ]]></script> 

Any server side code such as PHP or ASP.NET? If so, store the results of the age in a session variable so you can carry the value from one page to another.

Hi Jorge, sorry I don't understand what you mean by store the results of the age in a session variable. I don't want to carry the value to the next page. I want one time cookie where visitor visits the site and has to confirm his/hers age one time only. Thanks for answering.

Ok, so if you create a cookie, you simply need to check the value stored in that cookie on each page. If the cookie exists and the value stored is greater than the required value, then you dont prompt the user again. If the value is less, redirect the user letting them know they are not able to access your content. If there is no cookie, then prompt the user.

The session variable is also stored as a cookie, but destroyed at the end of the web browser session.

Thanks Jorge M, how do you put that on the code above?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.