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 of “username@server”. Due to the charm of "@", everyone has applied one after another. You may think: "How great it would be if I could provide such a service:) It must be very popular!" This article will unveil the "mystery" of "@" to everyone, so that everyone can come to "@"! (Do u @ today?)
Don't worry, this is not the email address, it is a virtual domain name. If you don't believe it, you can access "bbs@" in the browser. Some friends should have used the IE FTP function, which means that IE will automatically log in to the FTP server by typing "password:username@server" in the browser's address bar; while in the Http1.1 protocol, the Http access authorization function is also specified, the form is "password:username@server", where "password:" can be omitted, and it is also that accessing "bbs@" is actually accessing the "" server as bbs.
Then we just need to pass the specific URI to the PHP program and search for the real URL redirect in the database.
First, we need to create a page that transmits URI (as the default document of the server, generally named); this function can be implemented in JS Window object, the following source code:
<script>
= ‘?url=' + ;
</script>
The above code will redirect the browser to 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 ID
Domain char(20) NOT NULL, # Domain Name
Gotourl char(255) NOT NULL, #Real URL
);
Once the Table is established, you can start writing. The program is divided into three parts:
1. Analyze URL:
$url = preg_replace("/^http:\\/\\//I", "", $url); // Remove the "http://" in front of the URL, insensitive to upper and lower cases
$url = preg_replace("/@.+$/", "", $url); // Remove the part after "@"
Then, the remaining URL only contains the "username".
In order to apply to the database, the characters of Mingyan need to be processed:
$url = addslashes($url);
2. Search for the real URL:
Here, in order 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 = springf("SELECT gotourl FROM domain WHERE domain='%s';", $url); // Generate query string
$gotourl = $db->result($queryString); // Query to get results
3. Redirect:
There are many ways to redirect browsers in PHP, and here we use the simpler HttpHeader to implement it:
header(“location: $gotourl”);
Attached
In fact, the virtual domain name service of "" like NetEase is similar to the implementation method of "@", but "." needs to be at the cost of general DNS resolution worth 200 yuan, while "@" only needs:
1. Permissions to PHP/SQL database;
2. Real DNS resolution domain name.
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>
("url","nease","width=windth,height=height");
</script>
In order to be worthy of the "conscience of heaven and earth", the author did not add the complete program after the merge (scam the manuscript fee?). If you are lazy and need complete code (including additions, etc.), you can obtain it at or http://bbs@. I hope everyone has a good number of visits.
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 of “username@server”. Due to the charm of "@", everyone has applied one after another. You may think: "How great it would be if I could provide such a service:) It must be very popular!" This article will unveil the "mystery" of "@" to everyone, so that everyone can come to "@"! (Do u @ today?)
Don't worry, this is not the email address, it is a virtual domain name. If you don't believe it, you can access "bbs@" in the browser. Some friends should have used the IE FTP function, which means that IE will automatically log in to the FTP server by typing "password:username@server" in the browser's address bar; while in the Http1.1 protocol, the Http access authorization function is also specified, the form is "password:username@server", where "password:" can be omitted, and it is also that accessing "bbs@" is actually accessing the "" server as bbs.
Then we just need to pass the specific URI to the PHP program and search for the real URL redirect in the database.
First, we need to create a page that transmits URI (as the default document of the server, generally named); this function can be implemented in JS Window object, the following source code:
<script>
= ‘?url=' + ;
</script>
The above code will redirect the browser to 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 ID
Domain char(20) NOT NULL, # Domain Name
Gotourl char(255) NOT NULL, #Real URL
);
Once the Table is established, you can start writing. The program is divided into three parts:
1. Analyze URL:
$url = preg_replace("/^http:\\/\\//I", "", $url); // Remove the "http://" in front of the URL, insensitive to upper and lower cases
$url = preg_replace("/@.+$/", "", $url); // Remove the part after "@"
Then, the remaining URL only contains the "username".
In order to apply to the database, the characters of Mingyan need to be processed:
$url = addslashes($url);
2. Search for the real URL:
Here, in order 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 = springf("SELECT gotourl FROM domain WHERE domain='%s';", $url); // Generate query string
$gotourl = $db->result($queryString); // Query to get results
3. Redirect:
There are many ways to redirect browsers in PHP, and here we use the simpler HttpHeader to implement it:
header(“location: $gotourl”);
Attached
In fact, the virtual domain name service of "" like NetEase is similar to the implementation method of "@", but "." needs to be at the cost of general DNS resolution worth 200 yuan, while "@" only needs:
1. Permissions to PHP/SQL database;
2. Real DNS resolution domain name.
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>
("url","nease","width=windth,height=height");
</script>
In order to be worthy of the "conscience of heaven and earth", the author did not add the complete program after the merge (scam the manuscript fee?). If you are lazy and need complete code (including additions, etc.), you can obtain it at or http://bbs@. I hope everyone has a good number of visits.