Home > Programming, Servers & Scripts >

Need a script to pull an audio file based on geo-location(state) (6)


07-02-2013 03:48 AM #1 HebrewHammerTN (Member)
Need a script to pull an audio file based on geo-location(state)

Just like the title says. Just need some code that will pull in an audio file based on the state the user is based in.

If they are in Arizona, the Arizona file gets pulled in.

Coding for speed would obviously be preferable.

More than willing to pay for a good fix to this problem


07-02-2013 10:38 AM #2 caurmen (Administrator)

This one should be pretty simple to do, actually!

The geolocation script that STM user peanut posted over here already does most of what you need.

Just replace each case statement with some HTML for the audio player you want to use.

For example, if you were using Audio.js:

Code:
switch($countrycode) {
    case 'US':
        echo '<audio src="/mp3/juicyUS.mp3" preload="auto" />'
        exit;
    case 'CA':
        echo '<audio src="/mp3/juicyCA.mp3" preload="auto" />'
        exit;
etc.

Hope that helps!


07-02-2013 12:39 PM #3 bbrock32 (Administrator)

The code Caurmen posted does the job just fine.


07-05-2013 09:05 PM #4 HebrewHammerTN (Member)

Hey Caurmen thanks for pointing me to that script!

So basically I would just replace "countrycode" with "regioncode" and set up the state's associated code below, right?


07-06-2013 11:43 AM #5 caurmen (Administrator)

In Peanut's original script, you'd need to replace the call to "geoip_country_code_by_addr" with "geoip_region_by_addr" and change the variable output to $regioncode:

Code:
$regioncodecode = geoip_region_by_addr($gi, $_SERVER['REMOTE_ADDR']);
After that, it should work as you say.

You MAY need the Maxmind Region Database - you would if you were using mod_geoip, but I'm not sure about the PHP include. It should be pretty obvious if so - it'll throw a large, obvious error.


07-06-2013 07:14 PM #6 HebrewHammerTN (Member)

Yeah, that's what I figured, and finally got the region database. Man, they seem a little odd in giving it out, made me jump over some hurdles. Script is working great now though

Thanks much!!!


Home > Programming, Servers & Scripts >