玩转虚拟域名
不知道大家最近上网是否发现一个新现象,就是有一些网站开始提供“username@server”的虚拟域名服务。由于“@”的魅力,大家纷纷申请,你或许会想:“如果我也能提供这种服务,该多好阿:)人气肯定不错!”本文将给大家揭开“@”的“神秘”面纱,让大家都可以来“@”!(Do u @ today?)
别急,这个并不是电子邮件的地址,是一种虚拟域名,不相信的话可以在浏览器中访问“bbs@zphp.com”。部分朋友应该使用过IE的FTP功能,就是在浏览器的地址栏中键入“password:username@server”IE就会自动登陆FTP服务器;而在Http1.1协议中,就规定了Http访问授权功能,形式同样为“password:username@server”,其中“password:”可以省略,也是是访问“bbs@zphp.com”实际上是以bbs的身份访问“zphp.com”这个服务器。
那么我们只是需要将具体的URI传送给PHP程序,在数据库中搜索出真实的URL重定向就可以了。
首先我们需要制作一个传送URI的页面(作为服务器的默认文档,一般命名为index.htm);在JS的Window对象中就可以实现这项功能,下面是index.htm的源代码:
上面的代码会将浏览器重定向到gotourl.php,并且通过QueryString给变量$url赋值为当前的URI。
成功将URI传递给PHP程序后,就可以进入数据库查找真实URL,下面是SQL数据库相对应的table 的结构:
CREATE TABLE domain(
Id int(3) UNSIGNED DEFAULT ‘0’ NOT NULL, # 域名ID
Domain char(20) NOT NULL, # 域名
Gotourl char(255) NOT NULL, # 真实的URL
);
建立好了Table,就可以开始编写gotourl.php了,程序分为三个部分:
1、 分析URL:
$url = preg_replace(“/^http:\/\//I”, “”, $url); // 将URL前面的“http://”去掉,不区分大小写
$url = preg_replace(“/@.+$/”, “”, $url); // 将“@”后面的部分去除
那么,剩下的URL就只含有“username”的部分了。
为了给数据库应用,需要对铭感的字符进行处理:
$url = addslashes($url);
2、 搜索真实的URL:
这里为了实现程序的通用性,使用了一个数据库的操作类(修改自PHPLib)来操作SQL数据库:
$db = new dbSql(); // 连接数据库
$queryString = sprinf(“SELECT gotourl FROM domain WHERE domain=’%s’;”, $url); // 生成查询字符串
$gotourl = $db->result($queryString); // 查询取得结果
3、 重定向:
在PHP中重定向浏览器有多种方法,在这里使用比较简单的HttpHeader来实现:
header(“location: $gotourl”);
附
其实像网易那样子的“username.yeah.net”的虚拟域名服务和“@”的实现方法大同小异,但是“.”需要以价值200元的DNS泛解析为代价,而“@”所需要的仅仅是:
1、 PHP/SQL数据库的权限;
2、 真正DNS解析的域名。
如果需要在虚拟域名服务中加入广告,比如网易的Popup窗口,可以将重定向部分改为:
为了对得起“天地良心”,笔者没有将合并后完整的程序加上来(骗稿费?),如果大家比较懒,需要完整的代码(包括了添加等等),可以在http://zphp.com或者http://bbs@zphp.com取得。希望大家都有一个好的访问量。

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



Websites for learning C language: 1. C Language Chinese Website; 2. Rookie Tutorial; 3. C Language Forum; 4. C Language Empire; 5. Script House; 6. Tianji.com; 7. Red and Black Alliance; 8, 51 Self-study network; 9. Likou; 10. C Programming. Detailed introduction: 1. C language Chinese website, which is a website dedicated to providing C language learning materials for beginners. It is rich in content, including basic grammar, pointers, arrays, functions, structures and other modules; 2. Rookie tutorials, This is a comprehensive programming learning website and more.

1. Use the win+x shortcut key to open the menu and select [Command Prompt (Administrator) (A)], as shown below: 2. After entering the command prompt interface, enter the [ipconfig/flushdns] command and press Enter , as shown in the figure below: 3. Then enter the [netshwinsockresetcatalog] command and press Enter, as shown in the figure below: 4. Finally enter the [netshintipreset] command and press Enter, restart the computer and you can access the Internet, as shown in the figure below:

Application method: 1. Apply for a free domain name through the Ministry of Industry and Information Technology website, and you can obtain the free domain name after waiting for approval; 2. Apply for a domain name for free through DNSPod. Users can register an account on DNSPod and apply for a free second-level domain name; 3. Choose a reliable domain name Free domain name service providers, choose a reliable provider through comparison and understanding; 4. Register an account, click the registration button, fill in the relevant personal information as required and create an account; 5. Search and select the domain name.

PHP domain name redirection is one of the commonly used technologies in website development. Through domain name redirection, users can automatically jump to another URL when visiting one URL, thereby achieving website traffic guidance, brand promotion and other purposes. The following will use a specific example to demonstrate the implementation method of PHP domain name redirection and show the effect. Create a simple PHP file named redirect.php with the following code:

When some friends are browsing the web, they find that their computer browser is obviously connected to the Internet but cannot open the web page. What is going on? Let's take a look at the solution to this problem. Win11 browser cannot open web pages but can access the Internet: 1. First click on the "three dots" of the browser. 2. Then click "View advanced settings". 3. Then select "Open proxy settings". 4. Finally, just turn on "Automatically detect settings". Extension: How to set compatibility mode

1. Choose an available domain name: The corporate email domain name should be related to the corporate brand or business. 2. Check whether the domain name has been registered: After selecting the corporate email domain name, you need to check whether the domain name has been registered by other companies. 3. Choose an email service provider: Enterprises can search for different email service providers through search engines and choose a provider based on their needs. 4. Create an account: The process of registering for an email service may be slightly different, but you usually need to fill in the basic information of the company and administrator and create an administrator account.

What should I do if Sogou High-speed Browser cannot access the Internet? When we use Sogou Browser, we cannot access the Internet. What should we do? Let’s introduce it below! We usually use Sogou Browser to browse the web, which is very convenient. However, recently some friends found that they could not access the Internet while using it. How should this situation be solved? What is the specific operation method? The editor has compiled it below How to solve the problem of Sogou high-speed browser being unable to access the Internet? If you don’t know how to solve it, follow me and take a look below! Solution to Sogou High-speed Browser unable to access the Internet 1. First, open "Sogou High-speed Browser" and click the "Menu Bar" above 2. Then click to expand "More Tools" 3. Next, click "Browser Repair" below 4. Finally Click on Quick Fix

Discuz Domain Name Modification Operation Guide In the process of using the Discuz forum system, sometimes we need to modify the domain name of the forum. It may be because the domain name needs to be changed, or some domain name resolution problems need to be repaired. This article will introduce in detail how to modify the domain name in the Discuz forum system, and give some specific code examples. 1. Back up data Before performing any operation, we must back up the data to prevent data loss due to operational errors. In Discuz, you can use the background data backup
