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

Play with virtual domain names◎+_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:04:031077browse

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:
<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); // Remove the part after the "@"
Then, the remaining URL only contains the "username" part.
In order to apply to the database, the characters need to be processed:
$url = addslashes($url);
2. Search for the real URL:

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445234.htmlTechArticleI don’t know if you have discovered a new phenomenon online recently, that is, some websites have begun to provide virtual domain name services for username@server . Because of the charm of @, everyone is applying, you may think...
Statement:
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