/    Sign up×
Community /Pin to ProfileBookmark

Is it possible to create subdomains using php

Hi,

I d like to know about the possibility of creating subdomains using php . Even an alternative would help until it helps to have the url format, [url]http://subDomainOrAlias.domain.com[/url]

BR

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@svidgenSep 09.2010 — The answer is probably yes.

Do you want a PHP script that will update DNS records for you? Or, do you want a PHP script that will "forward" HTTP requests to the appropriate files/scripts based on the HTTP Host header?

If you're looking for the 1st option ... umm ... find a DNS service with a nice API and let us know how it turns out ?

If you're looking for the 2nd option, see the HTTP_HOST environment variable: http://www.php.net/manual/en/reserved.variables.server.php


EDIT: In regards to the 2nd option, the assumption is that you've set up a wildcard host: [I]*.yourdomain.com A <your apache server's IP>[/I]
Copy linkTweet thisAlerts:
@GUIRauthorSep 10.2010 — Thanks for the info.. I will try for both ? . Btw would you be able to post a sample or link to a code sample how wild card host

BR
Copy linkTweet thisAlerts:
@svidgenSep 10.2010 — Set up a wildcard host -- ask your hosting provider for help with their DNS control panel if you're not sure how to do this. And then start with something like this:
[code=php]<?php
$valid_hosts = array(
'host1',
'host2',
'host3'
);

if (in_array($_SERVER['HTTP_HOST'], $valid_hosts)) {
require($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
} else {
require('404.inc');
}
?>[/code]


Make sense?
Copy linkTweet thisAlerts:
@GUIRauthorSep 10.2010 — Thanks for the informative reply.

BR
×

Success!

Help @GUIR spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...