New Zenner
- Join Date:
- May 2014
- Location:
- ohio
- Posts:
- 3
- Plugin Contributions:
- 0
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
<?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 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==-1 && !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!