Home > Backend Development > PHP Tutorial > Play with virtual domain names ◎+ ._PHP tutorial

Play with virtual domain names ◎+ ._PHP tutorial

WBOY
Release: 2016-07-21 16:07:16
Original
768 people have browsed it

Play with virtual domain names ◎+ .

I don’t know if you have discovered a new phenomenon on the Internet recently, that is, some websites have begun to provide virtual domain name services for “username@server”. Due to the charm of "@", people are applying one after another. You may think: "It would be great if I could also provide this kind of service:) It must be 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. 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:
<script> <br>this.location = 'gotourl.php?url=' + this.location.href; <br></script>
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
);
Once the Table is 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, it is not case sensitive
$url = preg_replace("/@.+$/", "", $url); // Replace the "@ "Remove
from the following 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:
in PHP There are many ways to redirect the browser, here we use the relatively simple HttpHeader to achieve it:
header(“location: $gotourl”);


Attachment

actually like The virtual domain name service of NetEase's "username.yeah.net" is very similar to the implementation method of "@", but "." requires DNS pan-resolution worth 200 yuan at the cost, while "@" only requires:
1. Permissions of PHP/SQL database;
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:
<script> <br>window.open("url","nease ","width=windth,height=height"); <br></script>

In order to be worthy of the "conscience of heaven and earth", the author did not add the complete program after the merger (cheating the manuscript fee?), 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.​

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/315226.htmlTechArticlePlay with virtual domain names◎+. I don’t know if you have discovered a new phenomenon on the Internet recently, that is, some websites have begun to provide Virtual domain name service for "username@server". Because of the charm of "@"...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template