Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    May 2014
    Location
    ohio
    Posts
    3
    Plugin Contributions
    0

    Default Setting age verification and cookie question, plase advise! ? :)

    Hi all! I hope I have posted this in the proper section! I've searched all over the place for days before posting this and have still been unable to solve the issue myself so I finally had to break down and ask for help. I am very new to making my own site, php, etc etc so please forgive me in advance if this is a no brainer for some lol! But I am trying to implement an age verification on my site. I have the proper code to do so I believe. I can get it working to a degree but not completely proper. I think the problem is the cookie is not being set properly. I need to know where to put the code I think. So here's the info. So I got some code off the web and followed the instructions, and where I got the code I also posted a request a few days ago but the post was very old so I don't know if it will get a response as it hasn't yet. So anyways. I created a page called verify.php and put it in the root directory with my store with the following code in the verify.php document.
    PHP Code:
    <?php
    /*
    */
    session_start();
    if(
    $_SERVER['REQUEST_METHOD']=='POST')
    {
    if(isset(
    $_POST['YES']))
    {
    $redirect=isset($_GET['return'])?urldecode($_GET['return']):'./';
    $expire=isset($_GET['x']) && is_numeric($_GET['x'])?intval($_GET['x']):-1;
    if(
    $expire==-1)
    {
    $_SESSION['verify']="yes";
    header("location: ".$redirect);
    exit(
    0);
    }
    if(
    $expire==0)
    {
    setcookie("verify""yes",mktime(0,0,0,01,01,date("Y")+30));
    $_SESSION['verify']="yes";
    header("location: ".$redirect);
    exit(
    0);
    }
    setcookie("verify""yes",(time()+$expire));
    $_SESSION['verify']="yes";
    header("location: ".$redirect);
    exit(
    0);
    }else{
    header("location: http://www.bing.com");
    exit(
    0);
    }
    }

    ?>
    <html>
    <head>
    <title>My website</title>
    </head>
    <body>
    <form action="" method="POST">
    <p>Are you over 18 years of age?</p>
    <input name="NO" type="Submit" value="NO - Leave" />
    <input name="YES" type="Submit" value="Yes - Enter" />
    </form>
    </body>
    </html>
    And then I put the following code
    PHP Code:
    function verify(){
        
    $redirect_url='verify.php';
        
    $expires=-1;
        
    session_start();
        
    $validated=false
        if(!empty(
    $_COOKIE["verify"])) { $validated=true; }
        if(!
    $validated && isset($_SESSION['verify'])) { $validated=true; }
        if(
    is_numeric($expires) && $expires==-&& !isset($_SESSION['verify'])) { $validated=false; }
        if(
    $validated) { return; }
        else {
        
    $redirect_url=$redirect_url."?return=".$_SERVER['REQUEST_URI']."&x=".$expires;
        
    Header('Location: '.$redirect_url);
        exit(
    0);
        }
    }
    verify(); 
    at the top of my zencart index.php and it works for one time. Like if I hit yes then im directed to my store but when I click on a product or link within my store I am redirected back to the verify.php and click yes again and it takes me back to the store and then I click on any other link,product or whatever and then I am redirected back to just a blank page.? Can someone please help me out? I have tried placing that last code within the main index.php, the includes/templates/mytemplate/index.php and header.html etc etc with no success. Is there a certain place in zencart where I should be placing a code for setting a cookie or is something wrong with my code or what? Any help is GREATLY appreciated! I'm losing my mind trying to figure it out and I know it's prolly a 5 second fix for some people. Thanks a bunch!

  2. #2
    Join Date
    Dec 2011
    Location
    Wisconsin, USA
    Posts
    674
    Plugin Contributions
    21

    Default Re: Setting age verification and cookie question, plase advise! ? :)

    My initial reaction is that there is either an issue with the "sequence of events" in your first section of code and/or our session settings. Are you bouncing between https/http ?

  3. #3
    Join Date
    May 2014
    Location
    ohio
    Posts
    3
    Plugin Contributions
    0

    Default Re: Setting age verification and cookie question, plase advise! ? :)

    No, i'm not bouncing between http and https. It's all http. With how much I've tried to fix this issue myself before asking for help, to be honest Im actually kinda glad the first response wasn't an instant 5 second fix! lol! I seriously wanna get something figured out tho cuz It's driving me insane! Thank you for taking the time to look at it and help me out! It's beyond greatly appreciated good sir!

  4. #4
    Join Date
    May 2014
    Location
    ohio
    Posts
    3
    Plugin Contributions
    0

    Default Re: Setting age verification and cookie question, plase advise! ? :)

    Oh and I should mention, I am not dead set on this code or anything. As long as it prompts a user even if they are linked from another site to a certain product or just type in the homepage, they are forced to at least click yes or no to the fact they are 18 at least once and then not bothered again for that session. Like this http://www.techerator.com/2010/09/ho...s-mmm-cookies/ That is the one I would really like to use so I can make the "verification" page styled like my site, but I cant seem to get that to work, following exact instructions. I think Im missing something in the instructions that someone with actually coding experience takes for granted lol!

 

 

Similar Threads

  1. v151 Age verification with cookie in header
    By castlepyro in forum Templates, Stylesheets, Page Layout
    Replies: 8
    Last Post: 28 Aug 2015, 05:55 PM
  2. v150 Age verification and restriction
    By clint6998 in forum General Questions
    Replies: 1
    Last Post: 27 Feb 2013, 09:57 PM
  3. Log in and Age Verification Required?
    By totalscrub in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 30 Jul 2009, 07:01 PM
  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