subdomain name and db lookups

hi ppl…

before i start telling what my problem is, i must inform you of the fact that i suck on jargons, but i understanding programming clearly.

So here is my problem:

I have a system at example.com that allows users to register and get subdomain names, and if a user types in the subdomain they can visit the user’s profile.

So the user table has:




id | username | domain | lastlogin



And one of the record is as




43 | chickenboy | chickenboy.user.com | 1242352234



So if you want to view the user’s profile you have to follow the link as:

example.com/index.php?r=user/view&id=43

however what i want to do is that a visitor can type in chickenboy.user.com and the visitor will automatically see the profile.

any idea how i can do this? without a redirection. I mean one of the way to solve this problem is to have the index php file at user.com to read the database and redirect to the example.com url. But i dont want to do that, i just want to have chickenboy.user.com to show the profile and thats the end of the story.

So far the setup is that

/var/www/example/Yii_app

/var/www/user/[no-files-here-yet]

So can you tell me how may i go with this.

The only solution that i know of currently is to have a user.com point to /var/www/example/, then at example/index.php check the hostname and forward as convenient - but this definitely isnt best practice…

so can u guyz plz helppp me out?? thnx

Moved to "General Discussion foxr Yii 1.1.x" as requested

Create a route:




return array(

 'http://<subdomain:\w+>.yourdomain.com'=>'user/view',

);



Then in your UserController in the actionView method you should check whether $_GET[‘subdomain’] is set. If so, load the User model using this instead of $_GET[‘id’].

You’re going to need to refine the URL route to ignore any other existing subdomains you are using (eg. www). And you’ll need wildcard domains set up on your server (unless you’re creating them individually).

thnx for your help appreciate it…

okay… here is the problem now.

if the user logins using example.com, then when he goes to his site: his-site.user.com the logins are lost… how do i make sure that the user stays logged in??

thnx!

You need to make sure the domain used by Yii to set the cookie is ".example.com". Like documented here.

You do this by setting the domain property of the CHttpCookie object of the component which sets the session cookie. You can configure it in your configuration file (probably main.php).

Check this out: http://www.yiiframework.com/wiki/135/single-sign-on-across-multiple-subdomains/

that help is for subdomain names… i need to do it for domain names… any help there??

That is a little more complicated. One solution is described here: http://www.15seconds.com/issue/971108.htm (scroll down to Sharing Cookies Between Domains).

Some solutions are proposed in this thread: http://www.yiiframework.com/forum/index.php?/topic/14563-single-sign-on/