大家在使用诸如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文件,去掉
设置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
if(strtok($usrinfo[$i],":")==$username){
$url=$usrinfo[$i+1];
}
if($url=="http://"){echo "not found the uesrname of Data!";}
else{
echo '';}
?>
摘自:http://www.zphp.com/power/tech_articles/list.php?id=212

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.

Fibers was introduced in PHP8.1, improving concurrent processing capabilities. 1) Fibers is a lightweight concurrency model similar to coroutines. 2) They allow developers to manually control the execution flow of tasks and are suitable for handling I/O-intensive tasks. 3) Using Fibers can write more efficient and responsive code.

The PHP community provides rich resources and support to help developers grow. 1) Resources include official documentation, tutorials, blogs and open source projects such as Laravel and Symfony. 2) Support can be obtained through StackOverflow, Reddit and Slack channels. 3) Development trends can be learned by following RFC. 4) Integration into the community can be achieved through active participation, contribution to code and learning sharing.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Chinese version
Chinese version, very easy to use

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function