Hi,

I want to restrict access to a forum to 10 local postcodes has anybody any ideas.
This is what I came up with so far-

function valid_postcode($postcode)
{
// check a postcode possibly belongs to Surrey or west sussex
if ($postcode == BN||CR||GU||KT||PO||RH||TN||TW)
return true;
else
return false;
}

and...

// POSTCODE NOT VALID
if (!valid_postcode($postcode))
{
echo 'That is not a local postcode. Please go back '
.' and try again.';

  exit;

}
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
been a long day stabbing in the dark.

Thanks for looking.

    That won't work. For a start you would need to quote the strings, or they are considered as (undefined) constants. Secondly, you would need to say

    if ( $postcode == "BN" || $postcode == "CR" // etc
    

    otherwise each check after the first would not actually compare against $postcode.

    A neater approach might be to use an array to contain the postcodes.

    function valid_postcode($postcode)
    {
      $postcodes = array ("BN", "CR", "GU"); // etc
      if(in_array($postcode, $postcodes))
      {
        return true;
      }
      return false;
    }
    

      cheers mate,
      The first options done the trick, I will try the 2nd when more read.

        Write a Reply...