Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

How to code multiple area_codes?

How to code multiple area_codes?

I'm using a redirect based on multiple area codes, I tried the below and when adding multiple area codes it doesn't work separated by a comma, is there another character I would use to separate each area code or do I have to list each one separately?

Code:

$app = &JFactory::getApplication();

if ( $geoip->area_code == "214,817,469,972,682" )
    $app->redirect("http://mydomain.com/dallas");

Thank you!

hominid4
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: How to code multiple area_codes?

Hi, sorry for the multiple posts, the below is working for me:

Code:

$app = &JFactory::getApplication(); 

if ( $geoip->area_code == "214" || "817" || "469" || "972" || "682" )
    $app->redirect("http://mydomain.com/dallas");

Thanks.

hominid4
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: How to code multiple area_codes?

Hi hominid4,

that code isn't going to work the way you think it will... you need to do it this way:

Code:

$app = &JFactory::getApplication();

$area = $geoip->area_code; // for convenience
if ( $area == "214" || $area == "817" || $area == "469" || $area == "972" || $area == "682" )
    $app->redirect("http://mydomain.com/dallas");

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: How to code multiple area_codes?

Awesome!  Yeah I was just playing with it more and it was acting weird, your code did the trick, thanks!

hominid4
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: How to code multiple area_codes?

Hi, one quick question regarding this.  I have area codes set up for different areas of Texas and just in case none of the area codes match I have MetaMod direct them (or keep them on) to the home page with an "else $app->redirect("mydomain.com/");".  The problem I having with that is it's causing a "too many redirects" error since the MetaMod is on the home page.

For those who are not redirected and stay on the home page is it possible to stop the redirects?  Would I have to use the 'show the module just once' recipe?:
http://www.metamodpro.com/metamod/recip … odule-once

Thanks!

EDIT:  Actually what I would need is an else statement at the end saying if you're on a computer that does not fall under one of the area codes then don't load the MetaMod module at all - is that possible?  For the computers that do fall under the area codes they should never be able to access the home page.  Thanks!

Edited By: hominid4
27-Sep-11 19:59:32

hominid4
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Re: How to code multiple area_codes?

Hi,

you just have the MetaMod on the home page, right?

If so, the code I gave you above should work as-is. If the area code is not matched, then no module will be displayed, and no redirection will be done. Isn't that what you want?

Cheers,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: How to code multiple area_codes?

Ah, well that's embarrassing!  Yes that was a fault in my thinking, I had the redirects for each region and at the end I told it that if the surfer didn't fall under any of the regions then redirect them to the home page.  I see what you're saying, I just don't put an else-statement for that.  Duh!

Thanks!

hominid4
Beginner Modder
ranks
useravatar
Offline
13 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5933
Total Posts Today:
2
User Info:
 
Total Users:
4366
Newest User:
chicagosepticpumping
Members Online:
2
Guests Online:
135


Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked