How to develop a virtual domain Name System _php Foundation

Source: Internet
Author: User
Tags strtok name database
Everyone in the use of such as such denoted domain name is very convenient, there are many people think: if I can make their own server can also achieve denoted domain name is good. It's not complicated, actually. After reading this article, you can also do a denoted domain Name System.

The key technology of denoted domain Name System is: to implement Web page redirection (redirctory). In essence, the denoted domain Name system is completely different from the virtual machine system. The virtual domain name and IP of the virtual machine exist one by one correspondence. The denoted domain Name system does not need to do one by one mapping domain names and IP. That is, it doesn't require a complex domain name resolution mechanism or a virtual machine, and it does what it does when you request Yourname.somedomain, redirecting your browser to where you originally stored the HTML page.

To illustrate the better, the following illustration:

I provide the source program is the operating environment is: RedHat 5.1 Linux under the Apache1.3.6 Web server +php3 language. Before we write a program, we need to set up our servers first. First, let the Apache server support PHP3. To download mod_php-2.0.1-9.i386.rpm, after installation, modify/etc/httpd/conf/http.conf file, remove #loadmodule php3_module a line in front of the # annotation number, Also in the/etc/httpd/conf/srm.conf file, remove the #addtype application/x-httpd-php3. PhP3, and add DirectoryIndex after the INDEX.PHP3 item. Restart Apache server, at which point the server supports standard PHP3 language script files and can use INDEX.PHP3 as the default home page.
Set up the DNS server so that it can resolve the generic domain name. Common UNIX and Linux system DNS resolution is done by the bind daemon, Bind4 and Bind8 configuration files/etc/named.boot and name.conf respectively, configured according to your system changes. Set the configuration file for Bind/etc/named.boot, in which you add the phrase "primary Db.domain", adding a new domain record. Add in/etc/name.conf:

Zone "" {
Type master;
File "Db.domain";
Create a new primary domain record file Db.domain in/var/name/in the format:
199811291; Serial
28800 refresh;
7200; retry.
604800; expire.
86400); minimum
MX Ten
www A
* A
The key is the last sentence, which points to the same IP for all hostname that may be unmarked throughout the domain. Perform/USR/SBIN/NDC reload and reload the domain name database. Test, at this time should be ping a domain of the host (except already marked), all point to the specified IP, then the DNS server settings completed.

The final step is to compile the PHP3 script. We have just explained the whole principle in detail in the diagram, so it is not very difficult to write a redirect program.

Let's look at a complete HTTP header message sent by IE5.0:

Accept:application/, Application/msword, Application/, Image/gif, Image/x-xbitmap, IMA Ge/jpeg, Image/pjpeg, */*
Accept-encoding:gzip, deflate
user-agent:mozilla/4.0 (compatible; MSIE 5.0b1; Windows 98)
We need to remove the host information from the entire HTTP header information and then separate the first part of the form, "www", that is, the hostname (name of the user registry). , as a keyword for redirection retrieval.

After retrieving the user's registered URL information, we send a redirect command "localtion:" to the user's browser to redirect the user to the specified page.

In PHP3, there is a function getallheader (), which gets the HTTP header information that the browser sends out. We basically need to use this function to complete the program.

The source program is attached to the back because it is only experimental nature, so in the query user information, do not use the database, if the entire system to the actual application, must be linked to the database, or query the user information process will be very long, greatly affect efficiency, and user data management is not convenient. (due to space limitations, do not give the registration and management of the required write-logging procedures, please add)

In the source program, all user information is recorded in the User.dat file in the data subdirectory. The format is:



Attached PHP3 source program:


Get HTTP ' s Header and parse it//

$headers = Getallheaders ();

while (the list ($header, $value) = each ($headers)) {

if ($header = = "Host") {$username = Strtok ($value, ".");}

Jump out the Banner ' s window//

Echo ' <script language= ' JavaScript > ',

' ("banner.htm", "sample",

"Toolbar=no", "Directories=no", "Directories=no", "Menubar=no");

' </script> ';

Seek the user information from the recorded file//

if (! $usrinfo =file ("Data/user.dat")) {echo "Open data File error!!";}

$url = "http://";

for ($i =0; $i <count ($usrinfo); $i + +)

if (Strtok ($usrinfo [$i], ":") = = $username) {

$url = $usrinfo [$i +1];


if ($url = = "http://") {echo "not found the uesrname of data!";}


Echo ' <meta http-equiv= "refresh" content= "0; ', ' url= ', $url, '" >}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.