Implementation of domain name steering system

Source: Internet
Author: User
Tags exception handling html page mysql php file php and php and mysql mysql database

Believe that many people love to make personal site friends have used classes such as http://yourname.yeah.net or http://yourname.126.com free three-level domain name, there are a lot of thinking: if I can make their own server can also achieve the domain name to turn to be good. It's not complicated, actually. After reading this article, you can also do a domain name steering system.

The key technology of the domain name steering system is to realize the redirection of Web pages (redirctory). In essence, the domain name steering system is completely different from the virtual machine system. The virtual domain name and IP of the virtual machine exist one by one correspondence. and the domain name steering system does not need the domain name and IP to do one by one mapping. That is, it doesn't require a complex domain name resolution mechanism or a virtual machine, and it does what it does when you request *.yourdomain, redirecting your browser to the actual address of the HTML page you're hosting.

Next we implement the domain name steering system step-by-step:

(assuming that your domain name is www.mydomain.com host address is 196.0.0.1).

First we set up DNS to point *.mydomain.com to our host address 196.0.0.1. (If you do not have your own DNS server you can skip this step and contact your domain service provider and ask them to point the *.mydomain.com to 196.0.0.1)

Win2000 DNS Management tool does not allow the host name to be filled in directly as * that is, we cannot directly point *.mydomain.com to the same IP address in the Win2000dns management tool. But we can do this by changing winnt\system32\dns\mydomain.dns this file. This file is saved in text format and can be opened by WordPad.

-->

We need to add a 196.0.0.1 record at the end of the article.

We update the server data files in the WIN2000 DNS management tool. You will find that there are more hosts "*" than we could have added directly to the mydomain.com domain. (Note: Your DNS settings will not take effect until a few hours later.) )

For this domain-switching system to run on multiple platforms we select the Php+mysql Production program section, please check if your Web server has PHP and MySQL installed:

We use index.htm to read the HTTP headers sent out by the browser to send the dns.php,dns.php query database to the address and return to the client.

Establish MySQL database mydomain

CREATE TABLE DNS (

Main char (60),

Link char (255)

)

Main to save *.mydomain.com's * part

Link is used to save the address of the corresponding direction of the domain name.

Establish index.htm:

<script>

This.location = "Dns.php?url=" +THIS.LOCATION.HREF;

</script>

Some friends will ask why not use PHP's Getallheader () function to get the HTTP header information from the browser. Because the function getallheader () only supports Apache Web servers, it is believed that most Win2000 users use IIS servers. Given the compatibility issue, we chose to use JavaScript to read the HTTP headers sent out by the browser.



Create dns.php file:

?

$domain = "mydomain.com"; Domain name

$database = "MyDomain"//Database

$datauser = "root"; Database users

$datapwd = ""; Database Password

$dataserver = "localhost"; Database server address

?>

?

$db =mysql_pconnect ($dataserver, $datauser, $datapwd);

?>

<!--analysis URL part-->

?

$url =str_replace ("http://", "", $url);

$url =strrev ($url);

$url =STRCHR ($url, Strrev ($domain));

$url =strrev ($url);

$main =str_replace (".".) $domain "," ", $url);

?>

<!--query Database part-->

?

$str = "Select link from DNS where main= ' $main '";

$result =mysql_db_query ($database, $str, $db);

List ($link) =mysql_fetch_row ($result);

?>

<!--exception Handling-->

<?if ($link ==null):?>

System error, or this domain name has not been registered!

<?else:?>

<!--steering Part-->

<meta http-equiv= "Refresh" content= "1; Url=http://<?echo $link;? > ">

<?endif;? >



Partial completion of the program.

The last thing to do is configure the Web server here we take iis5.0 as an example

Open the administrative tool for Internet Information Services and create a new site *.mydomain.com (note that you must make this site the default site for independent IP)

Make index.htm the default document for *.mydomain.com.

The domain name steering system has been implemented. You can add a piece of data to the database

Insert into DNS values ("Etechnic", "www.etechnic.com.cn")

As long as everyone in the browser input etechnic.mydomain.com can enter the Enet technology channel.

Here only to introduce the core content of the domain change, you just write a simple registration section can provide a free domain like my.yeah.net services. Or you can e-mail zjzf_1@163.net to me for free ASP cgi PHP version of the full domain name to the service program.

The program section is passed in Iis5.0+php4.0+mysql and Linux+mysql+apache tests. The lack of hope master enlighten.



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.