-1

I'm looking to create a basic postcode checker for a small business with a few stores across Australia. I just want the customer to input their postcode, and based on that postcode they would be redirected to their relevant local web site with local pricing etc. I was thinking just a simple if statement (e.g if submitted postcode is between 5000 and 5999 load South Australia page) but I'm not sure on how I would do this.

I have been looking at this: http://waww.com.au/ramblings/determine-state-from-postcode-in-australia but so far no luck

Any help would be appreciated!

Thanks

Ben Green
  • 41
  • 1
  • 1
  • 11
  • the function you refer looks very straightforward you can get state from `$state = findState($postcode)`. If you need more fine locality determination you may need to download the full postcode database and work with it. – bansi Jul 05 '14 at 12:49

3 Answers3

1

Although most people will tell you to use a database, don't!

The PHP function you posted is also the solution for your problem. It's ultra-fast, no connecting, no error handling, just call and forget. It might be possible to come up with a few optimizations, but at first glance it's just plain perfect to simply copy and use it. If it's becoming a bottleneck later on optimize it (the database would become a bottleneck thousands of years before this function does).

Fleshgrinder
  • 15,703
  • 4
  • 47
  • 56
1

If a database solution is not wanted, maybe try this ...

if ($postcode > 999 && < 2001) {$destination = "http://example.com/go_here"};
if ($postcode > 2000 && < 3001) {$destination = "http://example.com/go_elsewhere"};
// ...

header('Location: ' . $destination);
Johan Vranckx
  • 250
  • 3
  • 7
0

I would recommend you saving the postcode in the database with a relation (could be manytomany if there are multiple stores in one city) to the existing store. Then just search in the database for the entered code and redirect the user.

joelschmid
  • 828
  • 1
  • 16
  • 32