CodeIgniter Forums
Run function only once, when user enters web site - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Run function only once, when user enters web site (/thread-56301.html)



Run function only once, when user enters web site - El Forum - 12-08-2012

[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.


Run function only once, when user enters web site - El Forum - 12-08-2012

[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



Run function only once, when user enters web site - El Forum - 12-11-2012

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