Store Locator Script

category Categories:Scripts

Built a nifty store locator script today using zip codes held in a database, PHP and some MySQL queries. Here is a summary of how it works and the logic behind it. 

The Form:
A simple sleek looking form with some CSS applied for aesthetics.

Error Trapping:
The store locator uses several error trapping functions to prevent junk data being passed to the results page. For example, the demo form will only allow a 5 digit Maine zip code. Any other number will result in notifying the user to enter a valid zip code.

Results Page:
Once a valid zip code has been entered, the results page will then display all of your stores sorted by total miles. To help the user, the closest store will be shown first. Each store or location has latitude and longitude data held in a database, which the results page uses to calculate distance. If desired, the results page can also be converted to a Google map to help the visitor visualize your locations.

This script can be easily integrated into an existing website, if your web server can support it. Pricing depends on the scope of work (How many states covered, how many stores or locations, customizing the results page, google maps integration, etc.)

What is your website missing? 

Using BBClone with WordPress

I love using BBClone as a quick on the fly page counting system. BBClone is a website counter written in php and gives the user a quick summary of who is on their site and where that visitor came from.

Note:
This post will be very technical assuming the reader has a basic understanding of BBClone and the ability to edit your blog’s source code with a text editor.

For starters this is the snippet of code you will need:

<?php
define(’_BBC_PAGE_NAME’, $_SERVER['REQUEST_URI']);
define(”_BBCLONE_DIR”, “../website/bbclone/“);
define(”COUNTER”, _BBCLONE_DIR.”mark_page.php”);
if (is_readable(COUNTER)) include_once(COUNTER);
?>

There are two parts to this code that make it work with WordPress. The first is on the first line and is dark red. $_SERVER['REQUEST_URI'] will display this when a visitor hits a page:

bbclone sample

This is the complete path to the page minus the root directory.

Note:
If you are familiar with BBClone those stats will make sense. For readers not familiar with BBClone this tells me I had a hit to my Changing Measurements Shortcut in InDesign blog post with referer digg.com and with a search query of indesign.

The green text on line two: ../website/bbclone/ is the path where bbclone will write to. This will be different depending what directory contains the bbclone files.

I have not been able to get it to work except when adding the code manually to the source code of each page in my blog.

What I did was opened the following pages in a php text editor: 404.php, archive.php, index.php, links.php, page.php, search.php, single.php and then looked for this code:

<?php get_sidebar(); ?>
<?php get_footer(); ?>

I placed the snippet of code directly after the get_footer() function. When I tried to place the code in the actual footer.php file all I received was error messages, so this was the next best thing.

Good luck, leave a comment if you get stuck and I will try to help debug.


Clicky Web Analytics