|
While NetCloak INSERT commands are easy to use and a quick way to add new, dynamic features to your Web site, NetCloak's real power is in its ability to create conditional HTML. In other words, with NetCloak you can create pages that change in different circumstances- based on the user, browser or other conditions.
HIDE and SHOW Overview
- Think of your Web page as a stream of water flowing through a faucet. This analogy isn't far off the mark, as HTML pages are actually nothing more than text "streams" sent by your Web server, which is the "faucet". NetCloak SHOW and HIDE commands allow you to control the stream within the page, stopping the flow of text and then resuming it later.
Here is an example of the simplest possible HIDE and SHOW logic:
This line is visible to Web browsers.
<HIDE>
This line is not visible, even when users view the HTML source.
<SHOW>
The first line in this example will be sent to any remote Web browser under any circumstance (assuming there were no prior HIDE commands in the page). The HIDE command turns the stream of text going to the browser off. After the next line, which will be hidden from all browsers, a SHOW command is used to turn the stream of text back on.
The HIDE and SHOW commands, as used here, are unconditional. In other words, the <HIDE> command will always turn off the text stream and the <SHOW> command will always turn it back on. You are probably thinking that unconditional SHOW and HIDE commands are not very useful, and you are right. Conditional SHOW and HIDE commands are much better, and we will see them next.
NetCloak Note: The analogy of a stream of water flowing through a faucet has one flaw when taken literally. When you turn a faucet off, the water stops flowing through the pipe, and when you turn it back on, the flow of water resumes from where it left off. This is not the case with NetCloak. When you use a NetCloak HIDE tag, the text stream to the browser is interrupted but the page continues to be processed at the server, and when a SHOW command is encountered, the text stream to the browser resumes from that point. Text between the HIDE and SHOW commands is lost as far as the browser is concerned.
Adding Conditions
-
NetCloak HIDE and SHOW commands that depend on various conditions are much more useful than the unconditional ones. The conditions that the commands will depend on are actually information on the server, like the time of day, the value of a variable, or client's IP address, being the same or different from some specified value. In other words, NetCloak will compare the current value to some specified value (or values) and hide or show text following the command if the result of the comparison is true.
Some simple uses for this include showing a different message in the page depending on whether it is morning, afternoon or night; including text (or hiding text) from a certain number of visitors or on a certain day; or hiding links on the page based on where the user is loading the page from. This section has a few simple examples to introduce the concepts, and then will let you discover more commands and uses for them by exploring the user's guide. Once you are comfortable with the commands, you should also take a look at the more complex examples linked from the Introduction page.
Example: HIDE and SHOW by Time
- You can use NetCloak's SHOW_TIME command to have your server recognize the time and greet a user according to the hour:
<HIDE><SHOW_TIME EQUALS 05 06 07 08 09 10 11>
Good Morning!
<HIDE><SHOW_TIME EQUALS 12 13 14 15 16>
Good Afternoon!
<HIDE><SHOW_TIME EQUALS 17 18 19>
Good Evening!
<HIDE><SHOW_TIME EQUALS 20 21 22 23 00 01 02 03 04>
Good Night!
<SHOW>
Here in Chicago, it is <INSERT_TIME SHORT>.
The HIDE and SHOW TIME commands are based on a 24 hour clock, and here we specify multiple comparison constants. By using several constants, the command will be triggered if the current hour is equal to any of the hours specified. In this case, the first line turns on the stream of text on when the current hour is 05, 06, 07, 08, 09, 10, or 11. In other words, the stream is turned on if the current time on the server is between 5:00 a.m. and 11:59 a.m., and the server will then say "Good Morning!".
In any case, the next to last line unconditionally turns the stream back on for all cases with a SHOW command so that the server will send the current time following the greeting.
Here it is in action:
Good Morning!
Right now, it is 10:00.
You can use a similar technique with the HIDE_DATE command to show a message on specific date(s). See the User's Guide for details on the HIDE_DATE command.
NetCloak Tip: Any time you are using conditional commands that don't seem to be working, add the corresponding INSERT command to the page at the point where the HIDE and SHOW logic appears. In the example above, if the greeting message is incorrect during testing, the INSERT_TIME command will show the current time, which will help to resolve the difficulty. For example, if the server's clock is set incorrectly, the INSERT_TIME command will reveal the problem instantly.
Compatibility and Security
- If you are serving this page through NetCloak, use the View Source or Show Source command in your browser to compare the source of the previous example. Notice that the NetCloak commands do not appear at all... only the message appropriate to the current time ("Good Morning", "Good Afternoon", "Good Evening" or "Good Night") is sent to the browser. This is because NetCloak is processing the HIDE and SHOW commands on the server, before the HTML is ever sent to the browser.
Processing the commands on the server has two advantages: compatibility and security. Since only plain-vanilla HTML is ever sent to the browser, there is never any risk of incompatible browser versions. Your dynamic pages will always work no matter what browser the user views them in. This is true for search engines and other non-human browsers, too.
When the commands are processed on the server, they are never sent to the browser. Users cannot "peek" inside your dynamic pages to see what is going on or find information or options that are hidden by NetCloak. This means that no-one will steal your NetCloak code or see something you are hiding with NetCloak when they view the source of the page.
Example: Hiding Internal Links
- Consider a home page with a series of navigation links, like this:
<A HREF="/Contact.html">Contact Us</A>
<P>
<A HREF="/Help.html">Help Using This Site</A>
<P>
<A HREF="/InternalHome.html">For Employess Only</A>
<P>
In this example, the first two links on the page are intended for every user that comes to the page. The third link, however is for employees only. This page might provide a menu of local intranet applications, databases, Web management features, etc. While the internal only page may be password protected, it is much more secure for outside users to never see the link to the internal site. Outside users won't be curious or confused by links that they are unable to follow and are not meant to access.
NetCloak can be used to hide this link from outside users by checking the client's TCP/IP address. If the local network TCP/IP address range is from 192.168.1.1 through 192.168.1.255, for example, the internal only link can be hidden like this:
<A HREF="/Contact.html">Contact Us</A>
<P>
<A HREF="/Help.html">Help Using This Site</A>
<P>
<HIDE><SHOW_DOMAIN BEGINS 192.168.1.>
<A HREF="/InternalHome.html">For Employess Only</A>
<P>
<SHOW>
You can see above that SHOW and HIDE commands, like INSERT commands, begin with the full command name and are followed by parameters that specify the conditions when the SHOW or HIDE command will be triggered. Usually the parameter list begins with a comparison operator, followed by one or more values to be compared.
The interesting addition is the fifth line, which starts with an unconditional HIDE command. This turns the text stream off for all users. Immediately following this command is a SHOW_DOMAIN command, which will turn the text stream back on for any user whose TCP/IP address BEGINS with 192.168.1. In other words, the stream is turned back on only for users on the local network. The internal only link is then sent only to those users. When the HTML designed only for internal users is complete, a SHOW command turns the text stream back on for all users.
SHOW Never Hides, And HIDE Never Shows
- An important point to note in the above example is that the SHOW_DOMAIN command is preceded by a HIDE command. If the text stream is already on when a NetCloak SHOW command is encountered, then the result of the SHOW condition is irrelevant and the text stream will remain on after the command executes. To follow the water faucet analogy: if you want to have the faucet turned on only if a certain condition is true, you must first turn it off.
This behavior, at first, can lead to mistakes in creating conditional HTML, but ultimately it provides a great deal of flexibility in creating complex conditions. As you get started with NetCloak, just remember to preceed conditional HIDE commands with <SHOW>, and conditional SHOW commands with <HIDE>. Thinking in terms of SHOW and HIDE may take a little getting used to. Keep the faucet analogy in mind and soon you will get more comfortable with it.
NetCloak Tip: The examples shown here are used to SHOW and HIDE various text messages, but note that NetCloak can be used to control any HTML element. The text stream that is turned on and off can contain text, HTML formatting commands, embedded images, hypertext links, etc.
Example: Hide and Show with Counters
- Counters can also be used to create conditional HTML. Here is an example that will display a special message to the first 100 people that come to your Web site:
<HIDE><SHOW_COUNT Winners LT 100>
Congratulations, you are lucky visitor number <INSERT_COUNT Winners>!
<P>
<A HREF="winner.html">Click Here To Collect Your Prize</A>
<SHOW>
Here, when the counter "Winners" is Less Than ("LT") 100, the text will be displayed, the user will be told what visitor number they are, and a link will be shown to direct them to directions for claiming their prize. It is important to always use HIDE and SHOW COUNT commands along with an INSERT_COUNT command, since HIDE and SHOW COUNT will not increase the counter value. Without the INSERT_COUNT command, the "Winners" counter would never increase and the winner text would always be displayed, even after the first 100.
Example: Identifying Users with NetCloak
- Another common HIDE command is HIDE_USERNAME. This command can be used to present users with different information based on their access privileges. For example, let's say that both Bob and Tim have access to a Web page. While both users have access to the same Web page, a single item on that page can be hidden from Bob like this:
<SHOW><HIDE_USERNAME "Bob">
This message is for Tim only... Bob won't see it.
<SHOW>
Note that this is essentially the same as:
<HIDE><SHOW_USERNAME "Tim">
This message is for Tim only... Bob won't see it.
This has the effect in the first example of hiding the message from Bob but displaying it to everyone else, and in the second example the message is shown only to Tim but hidden from everyone else. Consider this carefully when building pages with conditional commands.
If there are only these two users the different examples above function identically. This will probably not be the case, though. The logic of the first is "hide only from Bob" and logic of the second is "show only to Tim". The first, as you can see, will be shown to everyone, not just Tim, but the second will be hidden from everyone except Tim.
Please note that the HIDE and SHOW PASSWORD commands will not force a password request of the user. They work based on passwords already entered. If you want to have the user's Web browser display a dialog box requesting the user to enter a password, you will need to use the NetCloak REQUEST_PASSWORD command, or some other security tool. NetCloak PASSWORD commands will properly act on the user's password, regardless of what security tool required the password initially. For example, if the user enters a password to gain access to a secure realm defined in your Web server software, the password will still be available to NetCloak for conditional processing.
Example: Tailoring Pages to Different Browsers
- One problem Web developers face is that different browsers on different platforms display HTML pages differently. For example, Windows browsers tend to display text larger than Mac browsers. Fortunately, NetCloak allows you to recognize the Web browser and create conditional HTML based on it. Here is the example:
<HIDE><SHOW_CLIENT CONTAINS "Win">
<FONT SIZE=-2>
<SHOW>
In this sample, the HTML FONT command will be sent to any client whose name includes "Win". NetCloak CLIENT commands are another excellent case where an INSERT command can be helpful. If you want to create conditional HTML based on the client type, use an INSERT_CLIENT command on a page, then load the page in several different browsers to see exactly how the browsers identify themselves.
Additional details on this particular technique can be found on the Maxum Examples Server.
By now, hopefully, the logic behind conditional HTML is starting to become clear. There are many more examples in the Commands section of the Reference Guide and on the Maxum Examples Server.
[ Move On To The Next Tutorial | Return To The NetCloak Introduction ]
|