Tutorial on virtual domain name ◎ +. _ PHP

Source: Internet
Author: User
Game virtual domain name ◎ + .. Play virtual domain name ◎ +. do not know if you have recently discovered a new phenomenon on the Internet, that is, some websites are starting to provide the "username @ server" virtual domain name service. Thanks to the charm of "@", the virtual domain name becomes ◎ +.

I don't know if you have recently discovered a new phenomenon on the Internet, that is, some websites are starting to provide "username @ server" virtual domain name services. Thanks to the charm of "@", you may want to: "If I can provide this kind of service, how nice it is? :) the popularity must be good !" This article will unveil the "mystery" of "@", so that everyone can refer to "@"! (Do u @ today ?)
Don't worry, this is not the e-mail address, is a virtual domain name, you can access the "bbs@zphp.com" in the browser if you don't believe it ". Some friends should have used the FTP function of IE, that is, entering "password: username @ server" IE in the address bar of the browser will automatically log on to the FTP server. in Http1.1, the Http access authorization function is also provided in the form of "password: username @ server", where "password:" can be omitted, it is also to access the "bbs@zphp.com" is actually to access the "zphp.com" server as a bbs.
Then we just need to send the specific URI to the PHP program and search for the real URL redirection in the database.
Sources source code:
Script
This. location = 'gotourl. php? Url = '+ this. location. href;
Script
The above code redirects the browser to gotourl. php and assigns the variable $ url to the current URI through QueryString.
After the URI is successfully passed to the PHP program, you can enter the database to find the real URL. The following is the structure of the table corresponding to the SQL database:
Create table domain (
Id int (3) unsigned default '0' not null, # domain name ID
Domain char (20) not null, # Domain name
Gotourl char (255) not null, # real URL
);
After creating a Table, you can write gotourl. php. The program is divided into three parts:

1. analysis URL:
$ Url = preg_replace ("/^ http: \\/\// I", "", $ url); // Set "http: // "remove, case insensitive
$ Url = preg_replace ("/@. + $/", "", $ url); // remove the part after "@"
The remaining URL contains only the "username" part.
To apply the log service to the database, you need to process the Ming characters:
$ Url = addslashes ($ url );
2. search for real URLs:
To achieve the universality of the program, a database operation class (modified from PHPLib) is used to operate the SQL database:
$ Db = new dbSql (); // connect to the database
$ QueryString = sprinf ("SELECT gotourl FROM domain WHERE domain = '% s';", $ url); // Generate a query string
$ Gotourl = $ db-> result ($ queryString); // Obtain the query result.
3. redirection:
There are multiple methods to redirect the browser in PHP. here we use a simple HttpHeader to implement:
Header ("location: $ gotourl ");


Appendix

In fact, the virtual domain name service of "username.yeah.net" like NetEase is similar to that of "@", but ". "It takes 200 yuan worth of DNS wildcard resolution, and" @ "only requires:
1. PHP/SQL Database permissions;
2. real DNS resolution domain name.

If you need to add an advertisement to the virtual domain name service, such as NetEase's Popup window, you can change the redirection part:
Script
Window. open ("url", "nease", "width = windth, height = height ");
Script

In order to be able to live up to the "conscience of heaven and earth", I did not add the complete procedure after the merger (fraud fee ?), If you're lazy and need complete code (including adding and so on), you can get it in http://zphp.com or http: // bbs@zphp.com. I hope everyone will have a good access volume.

Sorry. I don't know if you have recently found a new phenomenon on the Internet, that is, some websites are starting to provide "username @ server" virtual domain name services. Thanks to the charm...

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.