Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Apr 2011
    Posts
    6
    Plugin Contributions
    0

    Default Age verification with cookie in header

    First, thank you all that have posted help on this site. It has assisted me in numerous zencart installs for myself and friends.

    I am having a small problem with a age verification pop-up that I am trying to implement on a new install of zencart v 1.51
    the website is inaprops.com
    and I am trying to create a popup that will prompt the user to acknowledge that they are 18 or older before proceeding to the website. The popup is working correctly, but the cookie is not being created (at least when I look at the the site with firebug). Does anything pop out to anyone else with this code:

    <script type="text/javascript">

    function setCookie(cname,cvalue,exdays) {
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires=" + d.toGMTString();
    document.cookie = cname+"="+cvalue+"; "+expires;
    }

    function getCookie(cname) {
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1);
    if (c.indexOf(name) == 0) {
    return c.substring(name.length, c.length);
    }
    }
    return "";
    }

    var ofAge = getCookie("ofAge");
    if (ofAge != "true") {
    var answer = confirm ("Are you 18 or older?");
    if (answer = ok) {
    setCookie("ofAge","true",30);
    // document.location="http://www.inaprops.com"; // This line is not needed and will redirect the user back to the main page
    } else {
    alert('Sorry, we can not let you in!');
    document.location="http://www.google.com";
    }
    }

    </script>


    Thank you all in advance for any insight that you can give on this.

  2. #2
    Join Date
    Apr 2011
    Posts
    6
    Plugin Contributions
    0

    Default Re: Age verification with cookie in header

    Okay, I think I have the answer. I changed the lines int he bottom from:

    var ofAge = getCookie("ofAge");
    if (ofAge != "true") {
    var answer = confirm ("Are you 18 or older?");
    if (answer = ok) {
    setCookie("ofAge","true",30);
    // document.location="http://www.inaprops.com"; // This line is not needed and will redirect the user back to the main page
    } else {
    alert('Sorry, we can not let you in!');
    document.location="http://www.google.com";
    }
    }

    to:
    var ofAge = getCookie("ofAge");
    if (ofAge != "true") {
    var answer = confirm ("Are you 18 or older?");
    if (answer == true) {
    setCookie("ofAge","true",1);
    // document.location="http://www.inaprops.com"; // This line is not needed and will redirect the user back to the main page
    } else {
    alert('Sorry, we can not let you in!');
    document.location="http://www.google.com";
    }
    }

    </script>

  3. #3
    Join Date
    Nov 2011
    Posts
    54
    Plugin Contributions
    0

    Default Re: Age verification with cookie in header

    thanks for posting this. IT seems to be working for me with the change in your second post.

    For anyone who knows about this type of script. Where is the best place to put this? I currently have it in index.php but not at the top. When I put these types of scripts at the very top of indiex.php it changes my font size and spacing on the site.
    I put it towards the bottom of index.php and it seems to be working but I worry it might be causing other issues that aren't as obvious. Also worry if this can affect browser indexing etc. since the pop up gets in the way.
    Is there an ideal spot to put this script without causing any side effects? I want it to pop up when a person first comes to the site but just once.

  4. #4
    Join Date
    Jul 2012
    Posts
    16,816
    Plugin Contributions
    17

    Default Re: Age verification with cookie in header

    Quote Originally Posted by mysh View Post
    thanks for posting this. IT seems to be working for me with the change in your second post.

    For anyone who knows about this type of script. Where is the best place to put this? I currently have it in index.php but not at the top. When I put these types of scripts at the very top of indiex.php it changes my font size and spacing on the site.
    I put it towards the bottom of index.php and it seems to be working but I worry it might be causing other issues that aren't as obvious. Also worry if this can affect browser indexing etc. since the pop up gets in the way.
    Is there an ideal spot to put this script without causing any side effects? I want it to pop up when a person first comes to the site but just once.
    No, no, no...

    First of all, edits of index.php should be minimized to those absolutely necessary... Further some time and review of the way zen cart operates should be taken.

    The above script does the following: if a cookie hasn't been set validating the person is of age, then ask the person. If their answer is yes, then set/extend the cookie so that when the validation is attempted that it simply gets extended provided the cookie hasn't expired.
    If the person says no not of age, then they are redirected to google, no cookie is set. Next arrival at the site will cause the question to be asked again.

    As for how/where to place the above code. My suggeston would be to put it in a jscript_PICK_A_NAME.php file located in the includes/templates/YOUR_TEMPLATE/jscript directory. This way every page load will refresh the cookie.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    Join Date
    May 2015
    Posts
    21
    Plugin Contributions
    0

    Default Re: Age verification with cookie in header

    Not sure if this is the correct location for this or I should open a new thread, but I am encountering the following issue with a PHP based age verification: I am placing the following code in index.php
    PHP Code:
    session_start();
        if(! isset( 
    $_SESSION['age_verification'] ) or $_SESSION['age_verification'] != true ) die( header("Location: checkage.php?

    url=http://
    $_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]") );

        
    //session_destroy(); //

        
    echo 'hello over 18 person'
    Then I am placing a file called checkage.php in the root folder of my cart with the following code:

    Code:
    <?php
    
            // checkage.php
        session_start();
    
        // checkage.php
        if( isset( $_POST['yes'] ) )
        {
            $_SESSION['age_verification'] = true;
    
            if( isset( $_GET['url'] ) )
            {
                die( header('Location: ' . $_GET['url'] ) ); 
            } 
            else
            {
                die( header('Location: index.php') );
            }
        }
        elseif( isset( $_POST['no'] ) )
        {
            $_SESSION['age_verification'] = false;
        }
    
        // The below line will check if someone has already said no so you can show them a page which tells them to they are too young.
        if( isset( $_SESSION['age_verification'] ) and $_SESSION['age_verification'] != true ) die( header('Location: http://www.google.com' 
    
    );
    
        ?>
    
        <form method="POST" >
        <fieldset>
        <legend>Are you over 18?</legend>
        <input type="submit" name="yes" value="Yes" /> <input type="submit" name="no" value="No" />
        </fieldset>
        </form>
    It gives me a 500 internal error. Any suggestions as to what I'm doing wrong?

  6. #6
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,845
    Plugin Contributions
    25

    Default Re: Age verification with cookie in header

    PHP Code:
    if( isset( $_SESSION['age_verification'] ) and $_SESSION['age_verification'] != true ) die( header('Location: http://www.google.com'   ); 
    should be:
    PHP Code:
    if( isset( $_SESSION['age_verification'] ) and $_SESSION['age_verification'] != true ) die( header('Location: http://www.google.com'   )); 
    You missed a closing )

 

 

Similar Threads

  1. Setting age verification and cookie question, plase advise! ? :)
    By bruceallen in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 9 May 2014, 06:02 PM
  2. v150 Age Verification Script
    By jhowe in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 7 Aug 2012, 10:58 PM
  3. Age Verification or Restriction
    By Sweet ZouZou in forum General Questions
    Replies: 15
    Last Post: 10 Nov 2010, 09:46 AM
  4. Age Verification
    By signs in forum General Questions
    Replies: 0
    Last Post: 12 Jul 2009, 04:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg