Play the virtual domain name +.

Source: Internet
Author: User
Tags ftp php and query
Play the virtual domain name +.

I do not know if you have recently found a new phenomenon on the Internet, is that some sites began to provide "username@server" virtual domain Name services. Because of the "@" charm, we have to apply, you may think: "If I can provide this service, how good AH:" The popularity must be good! "This article will give you the" @ "the" mystery "veil, so that everyone can come to" @ "! (Do u @ today?)
Don't worry, this is not an e-mail address, is a virtual domain name, do not believe that the words can be accessed in the browser "bbs@zphp.com." Some friends should use IE ftp function, is in the browser's address bar type "Password:username@server" IE will automatically login FTP server, and in the Http1.1 protocol, the provision of HTTP access authorization, the same form as " Password:username@server ", which" password: "can be omitted, is also access to" bbs@zphp.com "is actually a BBS to access the identity of the" zphp.com "this server.
Then we just need to send the specific URI to the PHP program, in the database to search out the real URL redirect it.
First we need to make a page that transmits the URI (as the default document for the server, generally named index.htm), which can be implemented in JS Window object, and the following is the source code of index.htm:
<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 by QueryString.
After successfully passing the URI to the PHP program, you can go to the database to find the real URL, and 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 ID
Domain char not NULL, # domain name
Gotourl char (255) not NULL, # True URL
);
Set up a table, you can start writing gotourl.php, the program is divided into three parts:

1, Analysis URL:
$url = Preg_replace ("/^http:\\/\\//i", "", $url); Remove the "http://" in front of the URL, case-insensitive
$url = Preg_replace ("/@.+$/", "", $url); Remove the part after "@"
The rest of the URL, then, contains only the "username" section.
In order to apply to the database, grateful characters need to be processed:
$url = Addslashes ($url);
2, search the real URL:
In order to realize the universality of the program, a database operation class (modified from Phplib) is used to manipulate the SQL database:
$db = new Dbsql (); Connecting to a database
$queryString = Sprinf ("Select Gotourl from Domain WHERE domain= '%s ';", $url); Generate query string
$gotourl = $db->result ($queryString); Query to get results
3. Redirect:
There are a number of ways to redirect browsers in PHP, using simpler httpheader here:
Header ("Location: $gotourl");


Report

In fact, such as NetEase's "username.yeah.net" virtual Domain Name Services and "@" the implementation of the same approach, but "." Needs to be at the cost of a 200-dollar DNS pan-resolution, and "@" requires only:
1, the Php/sql database authority;
2, the real DNS resolution domain name.

If you need to add ads to the virtual domain name service, such as the popup window for NetEase, you can change the redirection section to:
<script>
window.open ("url", "Nease", "width=windth,height=height");
</script>

In order to be worthy of "heaven Knows", the author did not combine the complete procedure plus to (cheat royalties? If you are lazy, you need complete code (including additions, etc.) that can be obtained in http://zphp.com or http://bbs@zphp.com. I hope you all have a good visit 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.