CodeIgniter Forums

Full Version: Run function only once, when user enters web site
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
Is there some way to run function only once, when user load web site? I have a function which, based on the IP of the user, determines country of the user, and I need it to run at the start so that the language of the site is automatically set (via SESSION), and later if there is need, user can change language via button.

El Forum

[eluser]PhilTem[/eluser]
MY_Controller::__construct() business logic explained in words:

if ( session has no information about language )
check the language based on ip, etc. pp.
save the information in the session

El Forum

[eluser]ramirors[/eluser]
if ( !$this->session->userdata('country') ) $this->yourlibrary->set_ country();