Cloaking PHP

When creating a plain HTML site, you confront two paths: create a site that works great in only one browser, or create a mediocre site that works in all browsers. PHP allows you to create a site that works great in any browser. The HTTP_USER_AGENT variable contains the string most browsers send to the Web server to identify themselves. This variable may be used to choose between versions of content. This cloaks the inner workings of the site from the browser. A seamless experience is provided to visitors, despite differences in browser capabilities.

In most cases browser name and version are sufficient, though operating system is also helpful. My experience is that there are subtle differences between identical versions of browsers running on Windows or the Macintosh. One design element I have cloaked in the past is a JavaScript rollover, a graphic button that changes when the mouse is passed over it. For example, the label on the button may glow. This is accomplished in JavaScript by replacing the image. Unfortunately, this is not possible in older browsers. The code to accomplish this may be included only for browsers capable of executing it.

Another cloak I've used in the past involved graphic hard rules. An HTML trick is to create a single-pixel image and stretch it by setting the height and width attributes to values larger than one. This effect can be used to stretch the pixel into a line that becomes a hard rule. And unlike the HR tag, the rule can be any color. For older browsers that don't allow stretching of images, I send an HR tag instead to approximate the effect. Alternatively, I could have pointed to a graphic of the appropriate size.

Consider combining the strategy of cloaking with FreeEnergy. You can choose different layout modules for different browsers. The text-only Lynx browser doesn't allow you to arrange elements using HTML tables, as is customary, and may jumble your content. Because the content is separated from the layout code, you could create a Lynx-friendly version of an entire site by creating a single layout module.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

PHP Topics