|
|
![]() |
|
|
|
|||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|||||||||||||||||||
|
|
|
|
|
|
|||||||||||||||||||||||
|
|
|
|
|||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
||||||||||||||||||
|
|
|
|
|
||||||||||||||||||||||||
|
|
|
|
|
|
|
||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||
![]() |
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||
|
|
PHP Subdomains |
|
|
||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||
Today we are going to learn how to create a ‘fake’ subdomain using some basic PHP code. We have the option of either masking the URL (uniform resource locator; the address of a website) that the subdomain goes to, or not (masking is not possible if you are making subdomains’ for certain websites, Gmail, for example). Primarily I will be covering the method for masking the URL. Note: This tutorial assumes you already have a website with an ‘index.php’ page setup. Don’t worry if you don’t, open up Notepad, or your favorite code editor, and save the file with the name ‘index.php’ (make sure type of file is set to ‘any’). With the help of this tutorial, you will have setup as many subdomains’ as you want within a matter of minutes. Although some PHP knowledge will help, everything is explained throughout and you will pick up some skills along the way. Let’s go! The Limitations:
Followed by the rest of your website’s code… Also, these subdomains’ do not support email; for example, you would not be able to create the email address you@some.stuff.com with this script there is no way around this. These subdomains’ unfortunately aren’t search engine friendly either; so you won’t be seeing your subdomain listed in Google. The Requirements: How to do it:
The above code assigns the address a user types into their URL bar to the variable ‘$sub’, so that it can be easily used later in the script. Variables in PHP start with a ‘$’ sign and allow us to easily use a string or piece of data later in our script. This means that wherever we type the variable ‘$sub’ into our script, the URL the visitor tried to go to will be inserted. We can now use very basic code to check whether ‘$sub’ (the URL the visitor tried to navigate to) matches a pre-defined URL, and if so create an HTML frame which grabs the specified page and puts it over the top of ours. Remember, if it doesn’t then the contents of the rest of your page will be shown. Below the code we just inserted at the top of our page, put this code:
We have basically just made a big window over our website, which displays another website if a certain address is used to get to our site. One may ask the following question... This is so we can send the HTML frame code to the browser without the server thinking that it is PHP and trying to execute it. PHP code is executed on the server where it is hosted, and then the HTML output is sent to the browser; therefore it is very secure because a visitor cannot get access to the PHP code. But what if I don’t want to mask the URL?
As you can see there is some variation in the way the script is laid out, but the basic principal remains the same. This time the script is all in one PHP open and close tag because the redirect code is a PHP command and not HTML. If you read the rest of the tutorial thoroughly then you should have no problem understanding this code :P . And now you’re finished! |
|
||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||
|
|
|
||||||||||||||||||||||||||
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|