search
Homephp教程php手册玩转虚拟域名◎+

玩转虚拟域名◎+

Jun 13, 2016 am 11:20 AM
uInternet accessDiscoverdomain namestartsupplyHave funwebsitevirtual

不知道大家最近上网是否发现一个新现象,就是有一些网站开始提供“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的源代码:
<script> <br />this.location = &lsquo;gotourl.php?url=&rsquo; + this.location.href; <br /></script>
上面的代码会将浏览器重定向到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:

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

mPDF

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),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.