707Chapter 38PHP and JavaScriptYou could use a similar (Best web hosting)

707Chapter 38PHP and JavaScriptYou could use a similar division of labor with form validation. If JavaScript is enabled, youcan use it to make sure zip codes have nine digits, phone numbers have ten digits, and e-mailaddresses have both an @and a .. If JavaScript is not enabled, you can write a little PHPscript that will do the same things when the form is submitted and return the form with warn- ings if the values are bad. JavaScript form validation should be relied on only for quick convenience reminders, neverfor data sanitization. See Chapter 29 for more information on data security. Another kind of form is basically arithmetic a shopping cart with running totals or a mort- gage payment calculator. Again, you can combine both JavaScript and PHP in an arithmeticform to cover all the bases. Finally, there is one use where PHP is so much faster that you might want to replace JavaScriptaltogether: browser sniffing. This is done to send different versions of a file (for instance, astylesheet) to a visitor depending on which browser she s using. Server-side browser sniffingis vastly more efficient than client-side because no text is sent until the sniff has occurred. AJavaScript browser sniff can amount to hundreds of lines of JavaScript, which must be sent onevery download whether the correctly browser version has been detected or not. Listing 38-2shows a very simple server-side browser sniff. Listing 38-2:A server-side browser sniff (browsersniff.php) 0) { header( Location: index_ie.html ); } elseif (strpos($HTTP_USER_AGENT, Gecko ) > 0) { header( Location: index_moz.html ); } ?> Static Versus Dynamic JavaScriptAlthough the static JavaScript-PHP form in Listing 38-1 is handy for many applications, there sone big problem with it: You have to maintain it by hand. Every time you decide to add a newpage to your site, you ll have to remember to manually add it to the drop-down list. Big deal, you re thinking but these are the little things that become time-sucking nightmares whenyou re running a huge and high-traffic site. With PHP and a database, you can update some of your JavaScript automatically when newdata is stored in the database or, as we might say, dynamically. You want to take this optionwhenever possible, as it will help you save time in the long run. Listing 38-3 is how you drewrite the form in Listing 38-1 for even better client/server integration. Caution43
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Leave a Reply