943,524 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 3787
  • PHP RSS
Dec 14th, 2004
0

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

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Samantha-girl is offline Offline
2 posts
since Dec 2004
Dec 15th, 2004
0

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

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.
Administrator
Staff Writer
Reputation Points: 1422
Solved Threads: 162
The Queen of DaniWeb
cscgal is offline Offline
13,645 posts
since Feb 2002
Dec 16th, 2004
0

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

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Samantha-girl is offline Offline
2 posts
since Dec 2004
Dec 27th, 2004
0

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

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
Reputation Points: 12
Solved Threads: 5
Junior Poster
ReDuX is offline Offline
127 posts
since Sep 2004
Jan 16th, 2005
0

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

Quote originally posted by ReDuX ...
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)
Reputation Points: 10
Solved Threads: 0
Newbie Poster
timo is offline Offline
1 posts
since Jan 2005
Jan 16th, 2005
0

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

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
Reputation Points: 12
Solved Threads: 5
Junior Poster
ReDuX is offline Offline
127 posts
since Sep 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Domain Manager Problem
Next Thread in PHP Forum Timeline: How do I add this to that to get this?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC