基于 PHP 的系统中的域名(国家)相关横幅

发布于 2024-09-14 13:44:26 字数 443 浏览 7 评论 0原文

我在我们的服务器上安装了一个基于 PHP 的 Youtube 克隆系统。

几个国家使用相同的系统。假设我有 3 个域,它们都指向同一个系统:
www.site.hr
www.site.ba
www.site.rs

它们都重定向到名为 www.site.tv 的网站

这 3 个国家/地区的语言非常相似,因此每个国家/地区使用相同的系统是有意义的,但在内部如果系统能够显示与该特定国家/地区相关的横幅,那就太好了。

最好的方法是什么?有可能吗? 我的想法是:
1)查找每个访问者的IP并检查它来自哪个国家或
2)创建3个子域hr.site.tv、ba.site.tv和rs.site.tv,它们都是
独立的系统但共享相同的数据库......

我知道第一个想法是有缺陷的,第二个想法是合理的。 你有更好的主意吗?

I have an PHP based Youtube clone system installed on our server.

The same system is used in couple of countries. Let's say that I have 3 domains that all point to the same system:
www.site.hr
www.site.ba
www.site.rs

They all redirect to some site named www.site.tv

These 3 countries have very similar languages so it makes sense to have the same system for every country, but inside the system it would be great to display banners related to that particular country.

What is the best way to do that, and is it even possible?
My ideas were:
1) to lookup every visitors IP and check from which country is it or
2) to create 3 subdomains hr.site.tv, ba.site.tv and rs.site.tv, which are all
separate systems but share the same database...

I know that first idea is flawed, and second one is plausible.
Do you have any better idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

浅听莫相离 2024-09-21 13:44:26

如果您不需要强大的系统,而只是添加为某些(大多数)用户设置横幅的可能性,您可以使用这个简单的解决方案:

www.site.hr redirects to www.site.tv?lang=hr
www.site.ba redirects to www.site.tv?lang=ba
www.site.rs redirects to www.site.tv?lang=rs

然后将 lang 参数存储在 $_SESSION 中并使用它当人们不断访问内部页面时显示相关横幅。

当会话中不存在该参数时(例如对于机器人),您需要有一个默认行为。

您将受益于很少的重复内容和对现有代码的很少的更改(我想)。

If you don't need a robust system but only add the possibility to set the banners for some (most) users, you might use that simple solution :

www.site.hr redirects to www.site.tv?lang=hr
www.site.ba redirects to www.site.tv?lang=ba
www.site.rs redirects to www.site.tv?lang=rs

then store the lang parameter in $_SESSION and use it to display the related banners as people keep visiting internal pages.

you'd need to have a default behaviour for the case when that parameter doesn't exist in session (for robots for instance).

you'll have the benefits of very little duplicate content and little change to the existing code (i suppose).

北风几吹夏 2024-09-21 13:44:26

IP 地址查找和 GeoIP 不可靠。嗅探 $_SERVER['HTTP_ACCEPT_LANGUAGE'] 不会有太大帮助,因为它们可能会返回相同的语言,或者如果用户更喜欢英语,则根本不会返回。

如果这些是您的内部横幅,建议使用子域或同一域内的不同 URL 路径。第三方广告提供商可能有自己的市场定位算法。

IP address lookup and GeoIP are not reliable. Sniffing $_SERVER['HTTP_ACCEPT_LANGUAGE'] won't be of much help because they may return the same languages, or not at all if user prefers English, for example.

Using subdomains, or different URL paths within the same domain, is recommended if these are your in-house banners. Third-party ad providers may have their own market-targeting algorithms.

撩发小公举 2024-09-21 13:44:26

您的想法 1) 可能适用于大多数情况,但有时用户会根据他们连接到互联网的方式而得到错误的想法,并给您带来诸如搜索引擎之类的问题,您可能希望为所有三个站点建立索引。

2)由于“所有独立系统”部分而存在问题。维护三个独立的代码库来完成本质上相同的事情是浪费精力,如果数据库结构必须适合所有代码库,那么对数据库结构进行更改将很棘手。

更好的选择是只有一个系统,但将其连接到所有三个域,并在其中添加一些逻辑以显示每个国家/地区的适当横幅。您可以将 Web 服务器配置为将三个域名视为别名,并将来自所有域名的请求发送到同一个 PHP 应用程序。在 PHP 中,您可以通过 $_SERVER['SERVER_NAME'] 形式获取客户端请求的站点名称。您可能正在使用一个框架或 PHP 库,它提供了一种不同的方式来在您的网站上提供特定于域名的内容。

客户端可能会发送您不期望的主机名,因此请确保您有允许的主机名白名单,并且如果您的服务器收到无法识别的内容,则会拒绝该请求。

your idea 1) will probably work for most cases, but sometimes users will get the wrong one depending how they connect to the internet, and gives you problems with things like search engines which you might want to index all three sites.

2) Is problematic because of the 'all separate systems' part. Maintaining three separate codebases to do essentially the same thing is a waste of effort, and it will be tricky to make changes to the database structure if it has to be suitable for all of them.

A better option is to have just one system, but connect it to all three domains, and put some logic inside it to display the appropriate banner for each country. You can configure your web server to treat the three domain names as aliases and send requests from all of them to the same PHP application. In PHP you can get the name of the site the client requested as $_SERVER['SERVER_NAME']. You might be using a framework or PHP library that provides a different way to have domain name specific content on your site.

It's possible clients could send a hostname you aren't expecting, so make sure you have a whitelist of allowable hostnames and your server rejects the request if it gets something it doesn't recognise.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文