i wish to make a site(http://example.com) and allow user to create their own site under http://example.com. When a user register in my site automatically generata a subdomain for that user. thatis http://user1.example.c om. The actual files of the user in my server look like this /wwwroot/userfiles/user1. and also i have to make a small banner on each file,user uploaded. Can u help me?
create dynamic sub domain
Collapse
X
-
[PHP]<? function selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = strleft(strtolo wer($_SERVER["SERVER_PROTOCO L"]), "/").$s; $port = ($_SERVER["SERVER_POR T"] == "80") ? "" : (":".$_SERVE R["SERVER_POR T"]); return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); } ?>[/PHP]
put that out of the way somewhere, it basically splits your URL.
[PHP]<?
$url = explode("://", selfURL());
$url2 = explode(".", $url[1]);
$sub = $url2[0];
if($sub != "yourDomain ") {
header('locatio n: http://yourDomain.com/'.$sub); } ?>[/PHP]
and theres a redirect, replace all instances of yourDomain with the part BEFORE the .com and AFTER the http:// (Or other respective piece of text). $sub will be your username. put thie BEFORE any html output. including php echoes.
if you have any questions pm me or post here. -
i am extremely sorry. i forgot to finish the post
place these codes in the index.php page that you get when you first load your website. Place them at the top of your very first page, and adjust the URLs accordingly.
this way, when the page loads, it checks the URL, and when it sees the subdomain, it will re-direct to the folder with that domain as it's name. if there is no sub domain it keeps you on your home page.
See if this helpsComment
-
here is the link to the installation page.
maybe this will clairify things
Comment
-
i used this code in my index.php
<? function selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolo wer($_SERVER["SERVER_PROTOCO L"]), "/").$s;
$port = ($_SERVER["SERVER_POR T"] == "80") ? "" : (":".$_SERVE R["SERVER_POR T"]);
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI'];
}
function strleft($s1, $s2)
{ return substr($s1, 0, strpos($s1, $s2));
}
$url = explode("://",selfURL() );
$url2 = explode(".", $url[1]);
$sub = $url2[0];
//print $sub;
if($sub != "example") {
header('locatio n: http://example.com/'.$sub); }
?>
and also i created one account "user1"
when am using http://example.com it prints " example"
but when i'm using http://user1.example.c om it didnt print "user1" and 403 forbidden appeared in the browser.Comment
-
A very sloppily written code, i must say.Originally posted by eragonhere is the link to the installation page.
maybe this will clairify things
http://player-killer-clan.110mb.com/dsd.php?home.phpComment
-
the 403 is as i expected. your server is treating the user1.example.c om as an actual subdomain, and anything before your server is handled as part of an actual subdomain, not passed to the page, so im stuck there. and yes, i know, the code is sloppy, all my codes are, but it all works just the same.
have the people in the htaccess forum help you out, tihs goes beyond my knowledge
thank you anyway.Comment
Comment