如何在注册期间自动为用户分配sudomain

时间:2016-12-18 06:40:07

标签: php mysql .htaccess dns subdomain

我目前正在创建一个自定义应用程序,它涉及让每个用户拥有自己的子域,但我发现很难做到这一点。

我希望用户在注册时动态执行此操作。

如何使用PHP,import java.util.*; class TestClass { public static void main(String args[] ) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int a[]=new int[n]; int b[]=new int[n]; for(int i=0;i<n;i++) { a[i]=sc.nextInt(); b[i]=sc.nextInt(); } long sol=0; for(int i=0;i<n-1;i++) { for(int j=i+1;j<n;j++) { sol +=Math.abs(a[i]-a[j])*(Math.max(b[i],b[j])); } } System.out.println(sol); } } 和MySQL来完成这项工作?

这是我到目前为止所做的。

.htaccess

1 个答案:

答案 0 :(得分:0)

首先使用通配符DNS条目将所有子域指向您的服务器

*。example.com

当用户导航到user1.example.com时,让您的php脚本查找子域

$user = array_shift((explode(".",$_SERVER['HTTP_HOST'])));

检查用户是否存在于数据库中,或显示错误。

您现在拥有可用的用户名,可以使用该参数查询数据库。

当用户在您的网站上注册时,只需在数据库中创建用户,然后将其重定向到newuser.example.com