如何开发一个虚拟域名系统
大家在使用诸如yourname.yeah.net这样的简记域名时都感到十分方便,有很多人在想:我要是能让自己的服务器也能够实现简记域名就好了。其实这并不复杂。看完了本文,你也可以做一个简记域名系统。
简记域名系统的关键技术在于:实现Web页面的重定向(Redirctory)。在本质上,简记域名系统和虚拟机系统完全不同。虚拟机的虚拟域名和IP是存在一一对应关系的。而简记域名系统不需要将域名和IP做一一映射。也就是说,它根本不需要复杂的域名解析机制和虚拟机来完成,它所做的事情就是当你在请求yourname.somedomain时,将你的浏览器重新定向到你本来存放Html页面的地方。
为了说明的更完善,下面图例:
我提供的源程序是运行环境是:RedHat 5.1 Linux下的Apache1.3.6 Web服务器+PHP3语言。 在编写程序之前,我们首先要设置好我们的服务器。首先要让Apache服务器支持php3。到ftp.redhat.com下载mod_php-2.0.1-9.i386.rpm,安装后,修改/etc/httpd/conf/http.conf文件,去掉#LoadModule php3_module一句前面的#注释号,同样在/etc/httpd/conf/srm.conf文件里去掉#AddType application/x-httpd-php3 .php3前面的注释号,同时在DirectoryIndex一项后添加index.php3。重新启动Apache Server,此时服务器就支持标准的php3语言脚本文件了并能将index.php3作为默认的首页。
设置DNS服务器,使其能对泛域名解析。一般的Unix和Linux系统的DNS解析都是由Bind守护程序完成的,Bind4和Bind8的配置文件分别/etc/named.boot和name.conf,配置时根据你的系统修改。设置Bind的配置文件/etc/named.boot,在其中加入“primary domain.com db.domain”一句,添加一个新的域记录。在/etc/name.conf中加入:
zone "domain.com" {
type master;
file "db.domain”;
};
在/var/name/中新建主域记录文件db.domain,其格式为:
N SOA dns.domain.com root.domain.com (
199811291 ;Serial
28800 ;refresh
7200 ;retry
604800 ;expire
86400) ;minimum
dns
MX 10 dns.domain.com.
dns A 202.115.135.50
www A 202.115.135.50
* A 202.115.135.50
关键是最后一句,即将整个域可能出现未做标记的所有Hostname全部指向同一IP。 执行/usr/sbin/ndc reload,重新加载域名数据库。测试一下,此时应该随便ping一个domain域内的主机(除已经标记的),都指向了指定的IP,那么DNS服务器设置完成。
最后一步是编制PHP3脚本。我们刚才已经在图中详细的说明了整个的原理,所以写一个重新定向的程序就不是很难了。
让我们来看一个由IE5.0送出的完整HTTP头信息:
Accept: application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, image/gif, image/x-xbitmap, image/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)
我们需要在整个HTTP头信息中取出Host信息,然后将http://www.jj.jx.cn/www.xxx.xxx/default.htm形式的第一部分“www”,即HostName(也即是用户注册的name)单独取出,作为重定向检索的关键字。
检索到用户注册的URL信息后,我们给用户浏览器送一个重定向命令“Localtion: http://www.jj.jx.cn/somewhere/sample.html”,将用户重定向到指定页面。
在PHP3中,有函数GetAllHeader(),取得浏览器送出的HTTP头信息。我们主要需要使用此函数来完成整个程序。
后面附有源程序,由于只是实验性质的,所以在查询用户信息时,没有使用数据库,如果整个系统要实际应用的话,一定要和数据库挂接起来,不然查询用户信息的过程将是十分漫长,大大影响效率,而且用户数据的管理也不方便。(由于篇幅限制,没有给出注册和管理所需的写记录程序,请自行添加)
在源程序中,所有用户信息记录在data子目录下user.dat文件中。其格式为:
username:
http://octopus.cdit.edu.cn/~qap213/index.html
附PHP3源程序:
//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
$url=$usrinfo[$i+1];
}
if($url=="http://"){echo "not found the uesrname of Data!";}
else{
echo '';}
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

HTTP status code 520 means that the server encountered an unknown error while processing the request and cannot provide more specific information. Used to indicate that an unknown error occurred when the server was processing the request, which may be caused by server configuration problems, network problems, or other unknown reasons. This is usually caused by server configuration issues, network issues, server overload, or coding errors. If you encounter a status code 520 error, it is best to contact the website administrator or technical support team for more information and assistance.

HTTP status code 403 means that the server rejected the client's request. The solution to http status code 403 is: 1. Check the authentication credentials. If the server requires authentication, ensure that the correct credentials are provided; 2. Check the IP address restrictions. If the server has restricted the IP address, ensure that the client's IP address is restricted. Whitelisted or not blacklisted; 3. Check the file permission settings. If the 403 status code is related to the permission settings of the file or directory, ensure that the client has sufficient permissions to access these files or directories, etc.

Understand the meaning of HTTP 301 status code: common application scenarios of web page redirection. With the rapid development of the Internet, people's requirements for web page interaction are becoming higher and higher. In the field of web design, web page redirection is a common and important technology, implemented through the HTTP 301 status code. This article will explore the meaning of HTTP 301 status code and common application scenarios in web page redirection. HTTP301 status code refers to permanent redirect (PermanentRedirect). When the server receives the client's

How to use NginxProxyManager to implement automatic jump from HTTP to HTTPS. With the development of the Internet, more and more websites are beginning to use the HTTPS protocol to encrypt data transmission to improve data security and user privacy protection. Since the HTTPS protocol requires the support of an SSL certificate, certain technical support is required when deploying the HTTPS protocol. Nginx is a powerful and commonly used HTTP server and reverse proxy server, and NginxProxy

Use the http.PostForm function to send a POST request with form data. In the http package of the Go language, you can use the http.PostForm function to send a POST request with form data. The prototype of the http.PostForm function is as follows: funcPostForm(urlstring,dataurl.Values)(resp*http.Response,errerror)where, u

HTTP Status Code 200: Explore the Meaning and Purpose of Successful Responses HTTP status codes are numeric codes used to indicate the status of a server's response. Among them, status code 200 indicates that the request has been successfully processed by the server. This article will explore the specific meaning and use of HTTP status code 200. First, let us understand the classification of HTTP status codes. Status codes are divided into five categories, namely 1xx, 2xx, 3xx, 4xx and 5xx. Among them, 2xx indicates a successful response. And 200 is the most common status code in 2xx

Quick Application: Practical Development Case Analysis of PHP Asynchronous HTTP Download of Multiple Files With the development of the Internet, the file download function has become one of the basic needs of many websites and applications. For scenarios where multiple files need to be downloaded at the same time, the traditional synchronous download method is often inefficient and time-consuming. For this reason, using PHP to download multiple files asynchronously over HTTP has become an increasingly common solution. This article will analyze in detail how to use PHP asynchronous HTTP through an actual development case.

Common network communication and security problems and solutions in C# In today's Internet era, network communication has become an indispensable part of software development. In C#, we usually encounter some network communication problems, such as data transmission security, network connection stability, etc. This article will discuss in detail common network communication and security issues in C# and provide corresponding solutions and code examples. 1. Network communication problems Network connection interruption: During the network communication process, the network connection may be interrupted, which may cause
