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 PhP Program , Search for the real URL redirection in the database.
Optional Source code :
<SCRIPT>
This. Location = 'gotourl. php? Url = '+ this. Location. href;
</SCRIPT>
The above Code The browser will be redirected to gotourl. php, and the variable $ URL is assigned 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 integrated procedure (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.