473,396 Members | 1,998 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

create dynamic sub domain

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.com. 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?
Sep 30 '07 #1
9 2897
eragon
431 256MB
[PHP]<? function selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : ""; $protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); 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('location: 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.
Feb 3 '08 #2
where i place these php codes? Can u explain in details..
and thanks for ur help.
Feb 3 '08 #3
eragon
431 256MB
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 helps
Feb 4 '08 #4
ya i did these things. But i didnt get the output. Plz giv the step by step instruction,if u can.
Feb 5 '08 #5
eragon
431 256MB
did you get an error from the browser... if so, post it. i'm going to put a seperate page on my website with this script in it to test it. ill post my results and instructions.
Feb 8 '08 #6
eragon
431 256MB
here is the link to the installation page.

maybe this will clairify things

http://player-killer-clan.110mb.com/dsd.php?home.php
Feb 8 '08 #7
i used this code in my index.php

<? function selfURL() { $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s;
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]);
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('location: 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.com it didnt print "user1" and 403 forbidden appeared in the browser.
Feb 8 '08 #8
Markus
6,050 Expert 4TB
here is the link to the installation page.

maybe this will clairify things

http://player-killer-clan.110mb.com/dsd.php?home.php
A very sloppily written code, i must say.
Feb 8 '08 #9
eragon
431 256MB
the 403 is as i expected. your server is treating the user1.example.com 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.
Feb 9 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Roel Wuyts | last post by:
CALL FOR CONTRIBUTIONS International Workshop on Revival of Dynamic Languages http://pico.vub.ac.be/~wdmeuter/RDL04/index.html (at OOPSLA2004, Vancouver, British Columbia, Canada, October...
2
by: Keith Jakobs, MCP | last post by:
Greetings: I had seen several posts around the Internet about this issue from a few months back, but have been unable to find a resolution ... I have a user who is trying to get started with...
3
by: dgk | last post by:
Not a dotnet question yet, although the site will be dotnet. Anyway, I have a cable modem and dynamic (although pretty static) IP address. How can I use a domain name if the real ip can change? I...
0
by: Pascal Costanza | last post by:
Dynamic Languages Day @ Vrije Universiteit Brussel ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Monday, February 13, 2006, VUB Campus Etterbeek The VUB (Programming Technology Lab,...
0
by: Nick | last post by:
Hi eveybody, I need some help regarding the mecanism to put in place to be able to dynamically update a remote object when the assembly where it is defined is modified, and this whitout having...
7
by: tirrell payton | last post by:
Hello, I am attempting to validate my user's email addresses by sending them a link. However, I am having trouble concatenating the variable name (GUID) into the url. Im using C#: public...
7
by: Bilz | last post by:
I am planning to use the CSharpCodeProvider to generate some compiled functions in my app. In my current implementation, All of these functions are generated in one swipe... thus they all invoke...
3
by: Yas | last post by:
Hi everyone I am trying to create a DELETE Trigger. I have 2 tables. Table1 and Table2. Table 2 has all the same fields and records as Table1 + 1 extra column "date_removed" I would like that...
0
by: avadhesh33 | last post by:
As we wanr Dynamic Subdomains It means we want to allow any of text in place of "www" like.. abc.domain.com xyz.domain.com ....... *.domain.com
7
by: bprocopio | last post by:
Please help. I'm stumped. I need to create a dynamic variable in a procedure that will be used to update a variable of the same name in a table. i.e. the name in tblAnalysisScores are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.