Jump to content

Set cookie and postal code check


Recommended Posts



I'm struggling to make my site work with custom codes. I have a restaurant website which only does delivery to certain postal codes. Here's my scenario: first time visitors will get the postal code check page (postcodecheck.php) to validate their postal code. Only if their code matches the one in the array, they will be redirected to index.php and the cookie should be set so they don't have to go through the postal code check anymore for their next visit. If their postal code doesn't match one of the values in the array, they won't be redirected and the cookie shouldn't be set to prevent them to enter the site the next time they visit (because their cookie is being stored).


To keep it simple:


if visitor is first time visitor {

do postcodecheck

if {

in the postcodecheck array then redirect to index.php and set cookie

} else {

don't set cookie, can't go to index.php



How do I achieve this? I'm not a programmer...


Right now I have this in my index.php:


// do nothing
} else {
$two_months = 60 * 60 * 24 * 60 + time();
setcookie('been_here', true, $two_months);
header('Location: postcodecheck.php');


Thank you in advance.

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...