Archive for September, 2007

134Part IPHP: The BasicsExtended Example: An Exercise CalculatorChapters (Web host sites)

Monday, September 3rd, 2007

134Part IPHP: The BasicsExtended Example: An Exercise CalculatorChapters 7 through 10 of this book feature an extended example that will build on itself fromchapter to chapter. Starting with a simple HTML form and form handler, you will add conceptsas you move through string, array, math, and filesystem functions. At the end, you will havebuilt a simple exercise calculator system that allows you to figure out how many calories wereburned by your daily workouts and to store this information in a file. In this first episode, shown in Listing 7-3, we are simply going to move a string POSTvariablefrom a form to a form handler using PHP. This HTML form is called workout_calc_var.html. Listing 7-3:Simple HTML form (workout_calc_var.html)

Workout calculator (passing a variable)

Enter an exercise, and we ll tell you how long you d haveto do it
to burn one pound of fat.



Figure 7-3 represents the output of the preceding HTML.
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

133Chapter 7Passing Information between Pages?> without giving (Web design seattle) too

Sunday, September 2nd, 2007

133Chapter 7Passing Information between Pages?>

METHOD= POST >
All GET, POST, COOKIE, ENVIRONMENT, and SERVERvariables were made global by the register_globalsdirective in php.iniand were directly accessible by their names bydefault. This was bad for several reasons. For one thing, every so often a COOKIEvariable would acci- dentally overwrite a POSTvariable of the same name although the developer didn t want thatto happen. For another thing, it led to big, messy, undifferentiated global namespaces. Mostimportant, allowing variables to be set by user input is very insecure. The PHP world had fartoo many inexperienced coders writing things like: without giving too much thought to the idea that a cracker could easily just call this page with aGETvariable named allaccesspassset to 1 and negate the advantages of any password check. The PHP team, in its infinite wisdom, decided to phase out the practice of registering globals, forcing everyone to call his variables as indices in an array (for example, $_POST[ secretpassword ]). This had already been possible in PHP4, via arrays named $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_POST_VARS, and so on, but few developers had used this syntax; frankly, it was a lot of extra keystrokes for a small increase in security. So the PHP team alsotook this opportunity to rename these arrays with shorter names: $_GET, $_POST, $_COOKIE, $_ENV, and $_SERVER. These superglobal arrays also have one cool feature that may ameliorate some pain: They areautomatically global everywhere. This means, for instance, that you no longer have to passcookie values into a function or declare the $HTTP_COOKIE_VARSarray global before you canaccess those values in a function. This will help those who functionalize to the max and willbe a small amelioration for everyone else. As of PHP4.2, register_globalsis officially turned off by default, and the old-style variablearray names are deprecated. Sooner or later, the PHP team will make register_globalsnotwork any more. It will take quite a while to move the entire PHP community over to the newsuperglobal arrays, but we feel obligated to try to use them as much as possible in this bookto set a good example. Save yourself a lot of trouble in the future and start using superglobalarrays. Although register_globalsis still an available option in PHP5 s php.inifile, setting it toondoes not, as of this writing, provide access to variables outside of the superglobal arrays. Caution09
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

132Part IPHP: The BasicsFigure 7-2:A form displaying (Disney web site) array

Saturday, September 1st, 2007

132Part IPHP: The BasicsFigure 7-2:A form displaying array variablesBecause, ultimately, we just want to count how many Yesanswers there are, it would be cum- bersome to set each check box as a separate variable and then count them. As you can see inthe preceding code (line 93), with an array it is a simple matter of calling the count()func- tion. In many other situations, it takes less code to loop through an array than to separatelytest a bunch of strings. As you can see in the form HTML, the way you create an array variable with an HTML form isby using a name with a bracket after it. This can be an empty bracket, a bracket with an inte- ger inside like the one we used above, or a bracket with a string inside. When you understandarrays better and have an idea of what you want an array to do for you, it will be clearerwhich of these alternatives you need in any given instance. PHP Superglobal ArraysA change that has been coming for a long time in PHP is the gradual phasing out of automaticglobal variables in favor of superglobalarrays, which were introduced in PHP4. Understandingsuperglobal arrays before you understand arrays may present difficulties; if so, we recom- mend you read Chapter 9 and come back to this section later. In the good old days before PHP4.1, you could write a piece of code like this and expect it to work: Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

131Chapter 7Passing Information (Web hosting billing) between Pagescode in public? Yes

Saturday, September 1st, 2007

131Chapter 7Passing Information between Pagescode in public?
Yes

9. Have you ever refused an otherwise welcome sexual advancebecause you were debugging?
Yes

EOQUIZ; // —————— // Now for some logic// —————— echo $header_str; if (!isSet($_POST[ submit ])) { // First time, show the quiz formecho $quiz_str; } elseif ($_POST[ submit ] == Evaluate ) { // Count up the yes answers$num_affirm = count($_POST[ affirm ]); // Come up with 4 different blurbsif ($num_affirm >= 0 && $num_affirm <= 3) { $result_str =

Why even pretend to be something you reso clearly not?

n ; } elseif ($num_affirm >= 4 && $num_affirm <= 6) { $result_str =

Come back when you ve learned more craft, Grasshopper.

n ; } elseif ($num_affirm >= 7 && $num_affirm <= 8) { $result_str =

Pretty geeky, but not yet a CodeGod.

n ; } elseif ($num_affirm >= 9 && $num_affirm <= 10) { $result_str =

We re not worthy to be in the presence ofyour bad geeky self!

n ; } echo $result_str; } echo $footer_str; ?> Figure 7-2 illustrates the output of the preceding code.
You want to have a cheap webhost for your apache application, then check apache web hosting services.