Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8282971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:34:08+00:00 2026-06-08T10:34:08+00:00

currently I have an Zend application on default location www.example.com/{controller}/{action} but when a user

  • 0

currently I have an Zend application on default location
www.example.com/{controller}/{action}

but when a user visit from a specific country, how to detect their ip address and redirect them to this countryCode based url
www.example.com/uk/{controller}/{action}?

To detect the country from which the user are visiting I have written a helper:

require_once '../library/Ipinfo/ip2locationlite.class.php';

class Application_View_Helper_GetLocation extends Zend_View_Helper_Abstract
{
    public function getLocation()
    {

        $ipLite = new ip2location_lite;
        $ipLite->setKey('APIKEY');

        //Get errors and locations
        $locations = $ipLite->getCity($_SERVER['REMOTE_ADDR']);
        $errors = $ipLite->getError();

        $country = strtolower($locations['countryName']);

        return "$country";
    }
}

The above code will return the country name. If a user is visiting from France how can I rewrite the url so that the url becomes example.com/france/{controller}/{action}?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T10:34:10+00:00Added an answer on June 8, 2026 at 10:34 am

    Refactor your view helper into a Controller Plugin and redirect.

    A controller plugin can execute early in the request dispatch loop, therefore you can intercept a request and redirect to another response before any controller is loaded and rendered. Example below (warning, may contain bugs!)

    class App_Plugin_DetectCountry extends Zend_Controller_Plugin_Abstract {
    
        public function preDispatch(Zend_Controller_Request_Abstract $request) {
            $ipLite = new ip2location_lite;
            $ipLite->setKey('APIKEY');
    
            //Get errors and locations
            $locations = $ipLite->getCity($_SERVER['REMOTE_ADDR']);
            $errors = $ipLite->getError();
    
            $country = strtolower($locations['countryName']);
    
            //Check if set country equals detected country
            if (!isset($_COOKIE['country']) || $country !== $_COOKIE['country']) {
                $_COOKIE['country'] = $country;
                $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
                $redirector->gotoUrl($country . '/' . $request->getControllerName() . '/' . $request->getActionName()); 
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am developing an application with the Zend Frameworks. I currently have the Controller
I'm working on Zend application, but have no much experience with Zend, so just
I'm currently building a web application (utilizing Zend Framework) and have gotten some of
I currently have url like localhost/zend_practice/countries/index?data=1 where countries is the name of my controller
Currently have a drop down menu that is activated on a hover (from display:none
I currently have a deployed app (fortworth.herokuapp.com) that I am attempting to sort movies
All, I have the following Zend application structure: helloworld - application - configs -
All, I have the following Zend application structure: helloworld - application - configs -
currently, to login a user in Zend Framework, i do something like public function
I currently have Zend setup to look for a layout script in each module's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.