I don’t know if you have discovered a new phenomenon on the Internet recently, that is, some websites have begun to provide “username@server” virtual domain name services. Due to the charm of "@", everyone is applying one after another. You may be thinking: "How great it would be if I could also provide this kind of service:) It must be very popular!" This article will reveal the "mystery" of "@" to everyone. Veil, so everyone can come "@"! (Do u @ today?)
Don’t worry, this is not an email address, it is a virtual domain name. If you don’t believe it, you can visit “bbs@zphp.com” in your browser. Some friends should have used the FTP function of IE. Just type "password:username@server" in the address bar of the browser and IE will automatically log in to the FTP server; and in the Http1.1 protocol, the Http access authorization function is stipulated. The form is also "password:username@server", in which "password:" can be omitted. Accessing "bbs@zphp.com" actually accesses the server "zphp.com" as bbs.
Then we just need to send the specific URI to the PHP program and search for the real URL redirection in the database.
First we need to create a page that transmits URI (as the default document of the server, usually named index.htm); this function can be implemented in the Window object of JS. The following is the source code of index.htm:
The above code will redirect the browser to gotourl.php and assign the variable $url to the current URI through QueryString.
After successfully passing the URI 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
);
Table created , you can start writing gotourl.php. The program is divided into three parts:
1. Analyze URL:
$url = preg_replace(“/^http:///I”, “”, $url) ; // Remove the "http://" in front of the URL, case-insensitive
$url = preg_replace("/@.+$/", "", $url); // Remove the "@" after remove the
part, then the remaining URL will only contain the "username" part.
In order to apply it to the database, it is necessary to process the memorable characters:
$url = addslashes($url);
2. Search for the real URL:
In order to achieve the versatility of the program, use Created a database operation class (modified from PHPLib) to operate the SQL database:
$db = new dbSql(); // Connect to the database
$queryString = sprinf(“SELECT gotourl FROM domain WHERE domain='%s ';", $url); // Generate query string
$gotourl = $db->result($queryString); // Query to obtain results
3. Redirect:
Redirect in PHP There are many ways to direct the browser, here we use the relatively simple HttpHeader to achieve it:
header(“location: $gotourl”);
Attachment
In fact, it looks like NetEase’s “username.yeah.net The implementation method of "virtual domain name service" is similar to that of "@", but "." requires DNS pan-resolution worth 200 yuan, while "@" only needs:
1. PHP/SQL database Permissions;
2. Domain name resolved by real DNS.
If you need to add advertisements to the virtual domain name service, such as NetEase's Popup window, you can change the redirection part to:
In order to be worthy of the "conscience of heaven and earth", the author did not add the complete program after the merger (Fraud?), if you are lazy and need the complete code (including additions, etc.), you can get it at http://zphp.com or http://bbs@zphp.com. I hope everyone has a good visit volume.
http://www.bkjia.com/PHPjc/532396.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532396.htmlTechArticleI don’t know if you have discovered a new phenomenon on the Internet recently, that is, some websites have begun to provide the virtual version of "username@server" Domain Name Services. Because of the charm of "@", everyone applies one after another, you...