How to develop a virtual domain Name System _php Tutorial

Source: Internet
Author: User
Tags strtok name database
Everyone is very convenient to use précis-writers domain name such as yourname.yeah.net, a lot of people think: if I can make my server can also implement précis-writers domain name is good. Actually, it's not complicated. After reading this article, you can also do a précis-writers domain Name System.

The key technology of the précis-writers domain Name system is to implement Web page redirection (redirctory). In essence, the précis-writers domain Name system and the virtual machine system are completely different. The virtual domain name and IP of the virtual machine have a one by one correspondence relationship. The précis-writers domain Name system does not need to do one by one mapping of domain names and IPs. In other words, it does not require complex domain name resolution mechanisms and virtual machines to complete, and what it does is to redirect your browser to the place where you originally stored the HTML page when you requested Yourname.somedomain.

To illustrate the more complete, the following illustration:

The source program I provide is the operating environment: RedHat 5.1 Linux under the Apache1.3.6 Web server +php3 language. Before we write the program, we need to set up our server first. The first thing to do is to have Apache server support PHP3. To ftp.redhat.com download mod_php-2.0.1-9.i386.rpm, after installation, modify the/etc/httpd/conf/http.conf file, remove #loadmodule php3_module a line in front of the # comment number, Also in the/etc/httpd/conf/srm.conf file to remove #addtype application/x-httpd-php3. php3 the previous comment number, and add DirectoryIndex after index.php3. Restart Apache server, where the server supports the standard PHP3 language script file and can use INDEX.PHP3 as the default home page.
Set up the DNS server so that it can resolve the pan domain name. General 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 modification. Set the Bind profile/etc/named.boot, add a new domain record by adding the phrase "primary domain.com db.domain". Add in/etc/name.conf:

Zone "domain.com" {
Type master;
File "Db.domain";
};
Create a new master domain record file Db.domain in/var/name/in the following format:
N SOA dns.domain.com root.domain.com (
199811291; Serial
28800; refresh.
7200; retry
604800; expire
86400); minimum
Dns
MX Ten dns.domain.com.
DNS A 202.115.135.50
www A 202.115.135.50
* A 202.115.135.50
The key is the last sentence, all hostname that are likely to appear in the entire domain are pointing to the same IP. Execute/USR/SBIN/NDC Reload and reload the domain name database. Test, you should casually ping a domain host (except the marked), pointing to the specified IP, then the DNS server settings are complete.


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 redirected program.


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


Accept:application/vnd.ms-excel, Application/msword, Application/vnd.ms-powerpoint, Image/gif, Image/x-xbitmap, IMA Ge/jpeg, Image/pjpeg, */*
Accept-encoding:gzip, deflate
Accept-language:zh-cn
Connection:keep-alive
Host:ww.yahoo.com
user-agent:mozilla/4.0 (compatible; MSIE 5.0b1; Windows 98)
We need to remove the host information from the entire HTTP header, and then separate the first part of the http://www.jj.jx.cn/www.xxx.xxx/default.htm form, "www", which is the hostname (also known as the user registered name). As the keyword for the redirect retrieval.


After retrieving the URL information of the user registration, we send a redirect command "localtion:http://www.jj.jx.cn/somewhere/sample.html" to the user's browser to redirect the user to the specified page.


In PHP3, there is a function getallheader () to get the HTTP header information sent by the browser. We mainly need to use this function to complete the program.


Attached to the source program, because only experimental nature, so in the query user information, not using the database, if the whole system to actual application, it must be connected with the database, or query user information process will be very long, greatly affect the efficiency, and user data management is not convenient. (due to space limitations, do not give registration and management of the required writing procedures, please add yourself)


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


Username


Http://octopus.cdit.edu.cn/~qap213/index.html


Attached PHP3 source program:


  

Get HTTP ' s Header and parse it//


$headers = Getallheaders ();


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


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


Jump out the Banner ' s window//


Echo ';


 

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

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


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


}


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


else{


Echo '

?>

http://www.bkjia.com/phpjc/316490.html www.bkjia.com True http://www.bkjia.com/phpjc/316490.html techarticle Everyone is very convenient to use précis-writers domain name such as yourname.yeah.net, a lot of people think: if I can make my server can also implement précis-writers domain name is good. Actually ...

  • 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: info-contact@alibabacloud.com 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.