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 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 | | 1242352234

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

however what i want to do is that a visitor can type in 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 to read the database and redirect to the url. But i dont want to do that, i just want to have to show the profile and thats the end of the story.

So far the setup is that



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

The only solution that i know of currently is to have a 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(



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, then when he goes to his site: the logins are lost… how do i make sure that the user stays logged in??


You need to make sure the domain used by Yii to set the cookie is "". 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:

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: (scroll down to Sharing Cookies Between Domains).

Some solutions are proposed in this thread: