Game virtual domain name ◎ +.

Source: Internet
Author: User

Game virtual domain name ◎ +.

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.

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.