Archive for August, 2007

Web domain - the script will e-mail the administrator and he

Tuesday, August 21st, 2007

the script will e-mail the administrator and he or she can in turn check to see whether this was a valid request and there is something wrong with the page or server, or whether someone was just looking for pages or trying to sniff around where they weren t supposed to be. Apache s ErrorDocument Directive Error handling is an invaluable resource and a must have for Web developers to keep their sites up and running with the fewest end-user problems or complaints. If you rely on people contacting you to tell you about errors on your site, you will never get any decent input. Allowing the server to do this for you will greatly increase your success at running a smooth server. This section first looks at Apache s ErrorDocument method of error handling. Try It Out Using Apache s ErrorDocument Method First of all, you need to make some changes to the httpd.conf file to allow you to create a custom error page. Apache is usually set up by default to go to its own internal error pages, but you don t want that. You want Apache to go to your custom error page, no matter what error has occurred. To do this, you change the default settings to your own specific settings by following these steps: 1. Open up your httpd.conf file, and around line 750 or so, you will find some lines that look like this (if you do not have access to httpd.conf, the following can usually be added to a .htaccess file in the base directory of your Web site): # Customizable error responses come in three flavors: # 1) plain text 2) local redirects 3) external redirects # # Some examples: #ErrorDocument 500 The server made a boo boo. #ErrorDocument 404 /missing.html #ErrorDocument 404 /cgi-bin/missing_handler.pl #ErrorDocument 402 http://www.example.com/subscription_info.html 2. Change that information to the following, then restart Apache: # Customizable error responses come in three flavors: # 1) plain text 2) local redirects 3) external redirects # # Some examples: ErrorDocument 400 /error.php?400 ErrorDocument 401 /error.php?401 ErrorDocument 403 /error.php?403 ErrorDocument 404 /error.php?404 ErrorDocument 500 /error.php?500 How It Works You have just edited Apache s configuration file to help you with error handling. By using the ErrorDocument directive, you are able to send users to specific error pages depending on what error the server has encountered. For example, if you receive a 404 error, the typical Page Cannot Be Found page, you can redirect it to a page you have created to look like your Web site but still get the 252 Chapter 9
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

9 Handling and Avoiding Errors You will probably (Geocities web hosting)

Monday, August 20th, 2007

9 Handling and Avoiding Errors You will probably be spending a fair amount of time contemplating errors in your code, as do most Web developers when they start programming. No matter how good you are, how well you code, how long you have been coding, or how hard you try, you will encounter times when you have errors in your code. It is of the utmost importance that you know how to handle your errors and debug your own code. Being able to efficiently and properly debug your code is an invaluable time-saver; and in Web development, $time == $money! Luckily, PHP comes with a full-featured Applications Programming Interface (API) that provides you with many ways to trap and resolve those unwanted errors. PHP also allows you to use the API to capture the errors and create your own custom error functions or pages. These features are useful when debugging your code and when notifying your Webmaster about errors that seem to be happening to your applications as users are running them. Not only can you use PHP code to trap errors and customize them; you can use the Apache Web Server to help do this. How the Apache Web Server Deals with Errors Apache has a directive, the ErrorDocument, that you can configure in the httpd.conf file to create custom error pages with PHP so visitors to your site don t see the old, boring, server-created error pages. You have limitless possibilities when creating these custom messages. As with the PHP error-catching pages, you can have the ErrorDocument call PHP pages to do whatever you would like them to do from simply displaying a friendly error message to the user to e-mailing a system administrator to notify him or her of the failure. Unlike PHP error pages, the Apache ErrorDocument pages are used more for instances of missing pages (that is, a Page Not Found error or Forbidden access error pages and other requests of that sort). So, if someone visits your site, and he or she runs into the Page Not Found error page,
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

If mktime fails to create a timestamp from (Free web servers)

Sunday, August 19th, 2007

If mktime fails to create a timestamp from the date you passed to it, it will return -1. This happens when the input is invalid, although it matches the regular expression. For example, 99-99-9999 will pass the regular expression test but is obviously not a valid date. To be sure that the date is indeed a date, you test for the return value from mktime and respond accordingly. if ($movie_release == -1 ) { $error .= Please+enter+a+real+date+ . with+the+dd-mm-yyyy+format%21%0D%0A ; } In this case, a false date entry triggers an error message asking for a valid date. Here s an alternative technique: You could have performed the same timestamp generation using SQL. Many things that PHP does on the string manipulation side can be done straight from SQL, as shown here: if (!ereg( ([0-9]{2})-([0-9]{2})-([0-9]{4}) , $movie_release, $reldatepart) || empty($movie_release)) { … } $reldate = $reldatepart[ 3 ] . - . $reldatepart[ 2 ] . - . $reldatepart[ 1 ] . 00:00:00 ; $sql = INSERT INTO movie (movie_release) . VALUES (UNIX_TIMESTAMP( $reldate )) ; In this code, the SQL does the timestamp generation. The UNIX_TIMESTAMP() SQL function expects a YYYY-MM-DD HH:MM:SS (2004-12-05 02:05:00) format and creates a timestamp from it. In the code, you force the creation of the timestamp at 00:00 on the date of the movie release. You can save yourself some lengthy coding by using SQL features wherever possible. See documentation on MySQL date and time functions at www.mysql.com/doc/en/ Date_and_time_functions.html. Summary Validating user data is all about being prepared for the worst. Users make mistakes that s the nature of users. Most errors are unintentional, but some are made intentionally to deny the service. It happens every day. The developer has to help the system deal with user input errors. Regular expressions help you meet many user input validation challenges. Learning how to use them is often the key to success in an interactive system. Exercise 1. Add validation to make the lead actor and director selections required. 250 Chapter 8
We recommend cheap and reliable webhost to host and run your web applications: Coldfusion Web Hosting services.

match, but not 2. The same logic applies (Web design service)

Sunday, August 19th, 2007

match, but not 2. The same logic applies to the [0-9]{4} statement: The only difference is that you are expecting four digits in the number, which indicate the year part of the date. So, in English, it means I want my string to start with a number with two digits, followed by a hyphen, and then another group of two digits, and then a hyphen, and finish with a four-digit number. if (!ereg( ([0-9]{2})-([0-9]{2})-([0-9]{4}) , $movie_release, $reldatepart) || empty( $movie_release )) { … } This is exactly what your regular expression says. If the string matches your condition, you will split it in three different chunks, each chunk delimited with the parentheses. This cutting is performed by the ereg() function. If the $movie_release string matches the pattern, ereg will cut the string into parts and then store each part as an element of the $reldatepart array. Be sure to read the PHP manual about regular expressions at www.php.net/regex and consult a few tutorials to understand the real power of using regular expressions. (You can find a good starting tutorial at www.phpbuilder.com/columns/dario19990616.php3.) If the user entered the date 02-03-2004, the array would be as follows: Array ( [0] => 02-03-2004 [1] => 02 [2] => 03 [3] => 2004 ) As you can see here, the first index holds the whole string, and each remaining index holds a cut-off part of the string, delimited by the parentheses. Now that you have the date in an understandable format, you can change it into a timestamp using the mktime() function, which allows you to create a timestamp from chunks of dates. It is also a very useful function to manipulate dates. $movie_release = mktime(0, 0, 0, $reldatepart[ 2 ], $reldatepart[ 1 ], $reldatepart[ 3 ]); This code stores a timestamp from the day, month, and year information fed to the system in the $movie_release variable. The format is int mktime (int hour, int minute, int second, int month, int day, int year). The returned value is the number of seconds between January 1, 1970, and the specified date. See documentation at www.php.net/mktime for additional information regarding optional parameters such as daylight saving flag. 249 Validating User Input
Check Tomcat Web Hosting services for best quality webspace to host your web application.

. is_object, which determines if the variable stores (Web hosting company)

Saturday, August 18th, 2007

. is_object, which determines if the variable stores an object (remember this one when you try object-oriented coding using PHP; it is very useful) These functions are all documented in the PHP manual at www.php.net/variables. In this instance, the use of is_numeric allows you to make sure that the user has entered a numeric value. $movie_rating = trim($_POST[ movie_rating ]); if (!is_numeric($movie_rating)) { $error .= Please+enter+a+numeric+rating+%21%0D%0A ; } else { if ($movie_rating < 0 || $movie_rating > 10) { $error .= Please+enter+a+rating+ . between+0+and+10%21%0D%0A ; } } The code first cleans up the value of leading and trailing spaces with the trim() function (always try to be prepared for typos and mishaps) and then tests to see if the value is numeric. If it s not, the error message queue is fed; if it is, the code tests the value to see if it is between 0 and 10. If the value is not between 0 and 10, it adds an error message to the error message queue. The date validation is almost as simple to understand, if you know about regular expressions. Here s a closer look at it: $movie_release = trim($_POST[ movie_release ]); if (!ereg( ([0-9]{2})-([0-9]{2})-([0-9]{4}) , $movie_release, $reldatepart) || empty($movie_release)) { $error .= Please+enter+a+date+ . with+the+dd-mm-yyyy+format%21%0D%0A ; } else { $movie_release = @mktime(0, 0, 0, $reldatepart[ 2 ], $reldatepart[ 1 ], $reldatepart[ 3 ]); if ($movie_release == -1 ) { $error .= Please+enter+a+real+date+ . with+the+dd-mm-yyyy+format%21%0D%0A ; } } As you saw in this chapter s first exercise, you use the trim() function to clear all leading and trailing spaces in the received string to make sure your user entered something other than just a space. You can find the string manipulation functions at the PHP Web site at www.php.net/strings. You can find trim() and some other very useful functions there. The next statement contains two conditions. The first condition tests for a regular expression match. The regular expression is ([0-9]{2})-([0-9]{2})-([0-9]{4}) . What does this do? [0-9]{2} specifies that you want to check for numbers between 0 and 9 with two occurrences. For example, 02 will 248 Chapter 8
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

5. Try entering alphanumeric values in (Best web site) the rating

Friday, August 17th, 2007

5. Try entering alphanumeric values in the rating field, as in Figure 8-8 (which could easily have been a drop-down but is a text field for the purpose of the exercise). Figure 8-8 If the entered value is not in the 0 to 10 range, it will be refused. (Note that the decimals are not managed in this code and will be lost.) How It Works First, let s look into the type validating functions. In the commit.php code, you use the is_numeric() function. This function returns a Boolean TRUE if the value is indeed numeric and FALSE if not. More of these validating functions are available, including: . is_string, which checks to see if the value is of the string format . is_bool, which checks for Boolean type (TRUE, FALSE, 0, or 1) . is_array, which tells you if the variable holds an array 247 Validating User Input
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Web design careers - } break; } if (isset($sql) && !empty($sql)) {

Thursday, August 16th, 2007

} break; } if (isset($sql) && !empty($sql)) { echo ; $result = mysql_query($sql) or die( Invalid query: . mysql_error()); ?>

Done. Index

3. Now save the files, upload them, and open your browser to the site index. 4. Click any movie and try entering 2003-10-10 in the release date field. You will be brought back to the form with a nice, yet very explicit, message telling you what format to use, as shown in Figure 8-7. Figure 8-7 246 Chapter 8
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.

$sql = INSERT INTO people (people_fullname) . (Web domain)

Wednesday, August 15th, 2007

$sql = INSERT INTO people (people_fullname) . VALUES ( . $_POST[ people_fullname ] . ) ; break; case movie : $movie_rating = trim($_POST[ movie_rating ]); if (!is_numeric($movie_rating)) { $error .= Please+enter+a+numeric+rating+%21%0D%0A ; } else { if ($movie_rating < 0 || $movie_rating > 10) { $error .= Please+enter+a+rating+ . between+0+and+10%21%0D%0A ; } } $movie_release = trim($_POST[ movie_release ]); if (!ereg( ([0-9]{2})-([0-9]{2})-([0-9]{4}) , $movie_release, $reldatepart) || empty($movie_release)) { $error .= Please+enter+a+date+ . with+the+dd-mm-yyyy+format%21%0D%0A ; } else { $movie_release = @mktime(0, 0, 0, $reldatepart[ 2 ], $reldatepart[ 1 ], $reldatepart[ 3 ]); if ($movie_release == -1 ) { $error .= Please+enter+a+real+date+ . with+the+dd-mm-yyyy+format%21%0D%0A ; } } $movie_name = trim($row[ movie_name ]); if (empty($movie_name)) { $error .= Please+enter+a+movie+name%21%0D%0A ; } if (empty($_POST[ movie_type ])) { $error .= Please+select+a+movie+type%21%0D%0A ; } if (empty($_POST[ movie_year ])) { $error .= Please+select+a+movie+year%21%0D%0A ; } if (empty($error)) { $sql = INSERT INTO movie (movie_name,movie_year, . movie_release,movie_type,movie_leadactor, . movie_director,movie_rating) . VALUES ( . $_POST[ movie_name ] . , . . $_POST[ movie_year ] . , . $movie_release , . . $_POST[ movie_type ] . , . . $_POST[ movie_leadactor ] . , . . $_POST[ movie_director ] . , . $movie_rating ) ; } else { header( location:movie.php?action=add&error= . $error); } break; 245 Validating User Input
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

case movie : $movie_rating = (Web hosting account) trim($_POST[ movie_rating ]); if (!is_numeric($movie_rating)) {

Tuesday, August 14th, 2007

case movie : $movie_rating = trim($_POST[ movie_rating ]); if (!is_numeric($movie_rating)) { $error .= Please+enter+a+numeric+rating+%21%0D%0A ; } else { if ($movie_rating < 0 || $movie_rating > 10) { $error .= Please+enter+a+rating+ . between+0+and+10%21%0D%0A ; } } if (!ereg( ([0-9]{2})-([0-9]{2})-([0-9]{4}) , $_POST[ movie_release ] , $reldatepart)) { $error .= Please+enter+a+date+ . with+the+dd-mm-yyyy+format%21%0D%0A ; } else { $movie_release = @mktime(0, 0, 0, $reldatepart[ 2 ], $reldatepart[ 1 ], $reldatepart[ 3 ]); if ($movie_release == -1 ) { $error .= Please+enter+a+real+date+ . with+the+dd-mm-yyyy+format%21%0D%0A ; } } $movie_name = trim($_POST[ movie_name ]); if (empty($movie_name)) { $error .= Please+enter+a+movie+name%21%0D%0A ; } if (empty($_POST[ movie_type ])) { $error .= Please+select+a+movie+type%21%0D%0A ; } if (empty($_POST[ movie_year ])) { $error .= Please+select+a+movie+year%21%0D%0A ; } if (empty($error) ){ $sql = UPDATE movie SET . movie_name = . $_POST[ movie_name ] . , . movie_year = . $_POST[ movie_year ] . , . movie_release = $movie_release , . movie_type = . $_POST[ movie_type ] . , . movie_leadactor = . $_POST[ movie_leadactor ] . , . movie_director = . $_POST[ movie_director ] . , . movie_rating = $movie_rating . WHERE movie_id = . $_GET[ id ] . ; } else { header( location:movie.php?action=edit&error= . $error . &id= . $_GET[ id ]); } break; } break; case add : switch ($_GET[ type ]) { case people : 244 Chapter 8
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

Web host 4 life - ?> Movie release date (dd-mm-yyyy) >

Monday, August 13th, 2007

?> Movie release date (dd-mm-yyyy) > Movie rating (0 to 10) > >

2. Now open commit.php and modify it as follows (modifications are highlighted): From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.