Thursday, November 6, 2008

Load different application based on ip address in CI(CodeIgniter)

You can modify the default index.php that comes with codeigniter to load a different application based on ip address. Why would I want to do that? You ask. Well, this would allow you to host the main application on a single internal server. While allowing your other servers that face client application. What this means is that you can create the meat of multiple different sites/domain and host them on the one. Then you can access this internal server from the childs and they will display data to the clients. Basically you would create a domain/site, host one file on it to get site based on domain and other options and display it to client. You can also create some basic caching capability.

Add this basic code in your index.php file:

if($_SERVER["REMOTE_ADDR"]=="192.168.1.5")
$application_folder = "app";
else
$application_folder = "application";
Of course you could create an array and setup multiple domains with the index.php file that receives the site and sends it to the client. Everything would go thru the uri string and you can implement a highly encrypted string and licensing to the internal server with all apps on it. Then just make sure that same index.php file is on all supported domains. :)

No comments: