English 中文(简体)
serving different content based on the domain in codeigniter
原标题:

I m going to develop a website in codeigniter. But not sure if the methor i m going to use is the best approach. There will be many addon domains for the same site. But content will be filtered based on the domain used to visit the site.

For Example If a user comes from the domain siteusa.com then the content will be shown filtered accordingly specific user. If the user comes from siteuk.com/sitechina.com the content will be filetered accordingly etc...

I m planning to do something like this to detect the url and serve content

 $ref = getenv("HTTP_REFERER");
    echo $ref; 

Another problem I see is the baseurl setting of codeigniter, but i saw a solution for that here

/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://www.your-site.com/
|
*/

if(isset($_SERVER[ HTTP_HOST ]))
{
$config[ base_url ] = isset($_SERVER[ HTTPS ]) && strtolower($_SERVER[ HTTPS ]) ==  on  ?  https  :  http ;
$config[ base_url ] .=  :// . $_SERVER[ HTTP_HOST ];
$config[ base_url ] .= str_replace(basename($_SERVER[ SCRIPT_NAME ]),   , $_SERVER[ SCRIPT_NAME ]);
}

else
{
$config[ base_url ] =  http://localhost/ ;
}

Is this is the best method to do this? Is there any possible bottleneck I may get into?

The main domain of the site will be serving unfiltered content and each addon domain will filter it according to filter set for each domain from backend.

最佳回答

Are .htaccess rules an option for you perhaps? Note that CI also has the routes.php file for fine-grained control over URLs, but not at the domain level I think.

问题回答

I don t see any issue in doing it this way. This won t cause a bottleneck, as the additional functions have negligible overhead.

For what it s worth I m doing the same thing for a SaaS service I run where multiple websites (thousands) are pointed to the same code igniter installation. I haven t had any issues.

As for the filtering, just make sure that you have proper indexes setup as you will need to query by the HTTP_HOST variable.





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签