473,320 Members | 1,969 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,320 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 2892
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.