View Full Version : Creating sub-domains with php?
GCharb
03-16-2005, 01:24 PM
Hello all!
First time on the forum, well, at least first time I am posting! :)
Got a question here.
Is it possible to create and delete sub-domains with php or any other language?
Looking into automating things here, thanks for any replies.
Oh, I searched the forum first but di not fing anything on the subject.
Chill!
Gilles
Viper007Bond
03-16-2005, 03:08 PM
On a HostRocket server? As far as I know, no. I believe Apache's httpd.conf or whatever it's called needs to be modified and only CPanel has access to that.
On your own server? I don't see why not. It's just gonna modify the file that handles that.
All of that is assuming you have your DNS set up right.
GCharb
03-17-2005, 08:17 AM
Hello there and thanks for the reply!
My bad, forgot to specify.
Yeah, on the hostrocket server, just wrote a small online webpage creation tool, peoples can register automatically but cant seem to be able to make a sub-domain with php. I will try something diffrent!
Thanks again! :)
Viper007Bond
03-17-2005, 05:08 PM
Well, I take that back. If you're on a dedicated (or probably a semi-dedicated) HR server, you should have access to that.
http://www.liquidpulse.net/articles/php/general/dynamic_subdomains
theres your info man! just set the file.php to a folder thingy instead, and you can get the subdomains to go to a folder with the name! if you know php well you can edit that little snippet to do many different things. if you have any questions, email me at downhillbiker@shaw.ca
GCharb
03-23-2005, 10:13 PM
Hello again!
Thanks to both of you, will check that page right away. :)
Gilles
Mr. Popularity
03-27-2005, 03:02 AM
you COULD do this if the HR shared servers have mod_rewrite enabled... I'm not sure if cPanel does this or not.
mod_rewrite is a pain in the @$$ though. :)
GCharb
03-31-2005, 03:02 PM
Hello again!
Thanks to both of you, was very usefull and yes, it seems like a pain in the arse, but I am looking it up! :cool:
Gilles
GCharb
04-29-2005, 01:14 AM
Okay!
After some research and much trial and errors I finally got it, here is the code
Sorry but didnt put any comments
tested it on another account of mine, needs DNS wildcards to be on, sent a ticket to HR to set my account with it, no replies yet!
<?
$domain = "yourdomain.com";
$userdir = "users";
$default_page = "index2.php";
$sub = $HTTP_HOST;
$sub = eregi_replace("\.".$domain, "", $sub);
$sub = eregi_replace("www\.", "", $sub);
$sub = strtolower($sub);
if (is_dir("$DOCUMENT_ROOT/$userdir/$sub"))
{
else
{
header("Location: http://$domain/$userdir/$sub");
}
}
else
{
if (!$REQUEST_URI || $REQUEST_URI == "/")
{
include("$DOCUMENT_ROOT/$default_page");
}
else
{
header("Location: http://$domain$REQUEST_URI");
}
}
?>
Gilles
GCharb
04-29-2005, 08:54 AM
Hello again!
Made a mistake in the last code, here is the good one, sorry! :)
<?
$domain = "123klik.com";
$userdir = "pages";
$default_page = "index2.html";
$sub = $HTTP_HOST;
$sub = eregi_replace("\.".$domain, "", $sub);
$sub = eregi_replace("www\.", "", $sub);
$sub = strtolower($sub);
if (is_dir("$DOCUMENT_ROOT/$userdir/$sub"))
{
header("Location: http://$domain/$userdir/$sub");
}
else
{
if (!$REQUEST_URI || $REQUEST_URI == "/")
{
include("$DOCUMENT_ROOT/$default_page");
}
else
{
header("Location: http://$domain$REQUEST_URI");
}
}
?>
GCharb
04-29-2005, 08:58 AM
Darn!
Hehe, of course you need to insert your domain in $domain, the folder where you want to put your subdomain folders in $userdir and $default_page point to your main index file.
You put that code in index.html or index.php, then the code points to your default page if no subdomain we're inserted with the url or if the subdomain does not exist.
Gilles
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.