954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Can php allow me to create whatever.homepage.com address

I want to find out if php can allow me to create whatever.homepage.com using my web address. I want to point the whatever.homepage.com to the folder homepage.com/whatever. Will php allow me to do this? O is there another script that will allow me to do this?

Samantha-girl
Newbie Poster
2 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

In order to do this, your webhost will have to enter a DNS record for the subdomain so that their routers know to point it to your server. Then, you can use either a .htaccess or .cgi file (most likely PHP as well) to redirect the subdomain to a folder of your choice.

cscgal
The Queen of DaniWeb
Administrator
19,421 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 229
 

Well my webhosting company have told me of the DNS subdomain record however that will only point to another domain ie daniweb.homepage.com would point to daniweb.com. What I am trying to do is point daniweb.homepage.com to homepage.com/daniweb/. some one said it could be done via php and I came her to find out before I went off to learn a new script that I might not use.

So what you are telling me is that php cannot help me? yes - no?

Samantha-girl
Newbie Poster
2 posts since Dec 2004
Reputation Points: 10
Solved Threads: 0
 

Yes you can do this.
You can simply redirect users to the correct folder.
There are two ways to do this really. the first is static. i.e. you set up instances of each domain you intend using. The second is dynamic, the script redirects users blindly, depending on whatever they put in as a subdomain. For dynamic redirection wildcards is required on your DNS. If you are using a free dynamic dns for this site, i suggest you check your settings and enable wildcards if applicable.

I must mention that this only works with HTTP1.1 compliant browsers, Some HTTP1.0 do not post the details required to make this work ($HTTP_POST).
Your index.php:
[PHP]
$subdomain = explode(".",$HTTP_HOST);
$default = ("main.php");

/* Static
if($subdomain[0] == "folder1"){
header("Location:http://$HTTP_HOST/folder1/");
}elseif($subdomain[0] == "folder2"){
header("Location:http://$HTTP_HOST/folder2/");
// and so on...
}else{
header("Location:http://$HTTP_HOST/$default");
}
*/

// Dynamic
if(is_dir("$DOCUMENT_ROOT/$subdomain[0]")){
header("Location:http://$HTTP_HOST/$subdomain[0]");
}else{
header("Location:http//$HTTP_HOST/$default");
}
[/PHP]

In the case of dynamic redirection, the script checks to see if the folder exists before forwarding the user to the folder. If it does not, the user is redirected to the default. In this case, domain.com/main.php .

Hope this helps :)

ReDuX
Junior Poster
127 posts since Sep 2004
Reputation Points: 12
Solved Threads: 5
 

Yes you can do this. You can simply redirect users to the correct folder. There are two ways to do this really. the first is static. i.e. you set up instances of each domain you intend using. The second is dynamic, the script redirects users blindly, depending on whatever they put in as a subdomain. For dynamic redirection wildcards is required on your DNS. If you are using a free dynamic dns for this site, i suggest you check your settings and enable wildcards if applicable.

I must mention that this only works with HTTP1.1 compliant browsers, Some HTTP1.0 do not post the details required to make this work ($HTTP_POST). Your index.php: [PHP] $subdomain = explode(".",$HTTP_HOST); $default = ("main.php");

/* Static if($subdomain[0] == "folder1"){ header("Location:http://$HTTP_HOST/folder1/"); }elseif($subdomain[0] == "folder2"){ header("Location:http://$HTTP_HOST/folder2/"); // and so on... }else{ header("Location:http://$HTTP_HOST/$default"); } */

// Dynamic if(is_dir("$DOCUMENT_ROOT/$subdomain[0]")){ header("Location:http://$HTTP_HOST/$subdomain[0]"); }else{ header("Location:http//$HTTP_HOST/$default"); } [/PHP]

In the case of dynamic redirection, the script checks to see if the folder exists before forwarding the user to the folder. If it does not, the user is redirected to the default. In this case, domain.com/main.php .

Hope this helps :)


I'm just starting out with php and this is exactly what i want to do
however i'm not sure how to impliment the example you give
i.e. does this example run as a script on the default webpage for the domain
(would i put this in domain.com/index.html)
or does the example need to be a .php file that is actioned by a page?

as I said I probably sound like a 1 year old trying to say "dadda" but please help if you can withstand my ignorance :)

obviously the static way would be best for my to try out
(although i think i can use wildcard for dns, so once i get a clue i might try the dynamic way)

timo
Newbie Poster
1 post since Jan 2005
Reputation Points: 10
Solved Threads: 0
 

That example would be the default 'index.php' page for your domain i.e.
http://www.domain.com/index.php
It will then be run, and depending on the subdomain you requested, it will direct to the page 'main.php' in the subfolder requested.
e.g. requesting the site/page http://pancake.domain.com will direct the users browser to http://www.domain.com/pancake/main.php

Hope that mekes it a little more clear :)

ReDuX
Junior Poster
127 posts since Sep 2004
Reputation Points: 12
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You