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?

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.

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?

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:

$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");
}

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 :)

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:

$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");
}

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)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.