Archive for August, 2007

Notice that Beginning was output because it was (Web site hosting)

Friday, August 31st, 2007

Notice that Beginning was output because it was before the function call, but End was not because the fatal error halted the script execution. You can suppress the fatal error calls by putting an ampersand in front of the function call, like so: @fatalerror(). This suppresses the error, but the script still halts its execution. As of PHP4 the default error reporting does not show E_NOTICE errors. However, you may want to show them during development. Enabling E_NOTICE errors for debugging can warn you about possible bugs or bad programming practices. For example, you might use something such as $row[variable], but actually it is better to write this as $row[ variable ] because PHP will try and treat variable as a constant. If, however, it isn t a constant, PHP assumes it to be a string for the array. You can set error reporting by simply putting error_reporting(number), where number is the constant value in the table shown earlier in the chapter, in your PHP page. If you don t know at what level your error reporting is set, you can simply run the error_reporting() function without any arguments, like this: By default, all error handling is handled by PHP s built-in error handler, which tells you the error and displays the message associated with that error. The message displays the error type, the error message, the filename, and the line number where the error occurred. You may have noticed an error similar to this one in a previous code snippet: Warning: Wrong parameter count for str_replace() in c:FoxServwwwerrorhandlingerror1.php on line 8 Usually, letting PHP generate its own errors is fine, but with complicated applications you may want to catch the errors so you can do something specific with the error, such as notifying an administrator so he or she can look into the problem further. Try It Out Creating a Custom Error Handler You will now create a custom error handler to catch the errors and display a more friendly error message. 1. Edit the script used in the previous examples like this:

Page Error

; echo Errors have occurred while executing this page. Contact the ; echo administrator . to report errors

; echo Information Generated

; echo Error Type: $error_type
; 263 Handling and Avoiding Errors
If you are in need for chaep and reliable webhost to host your website, our recommendation is http web server services.

If you run this snippet, you should (Web design careers) see

Friday, August 31st, 2007

If you run this snippet, you should see the following error: Warning: Wrong parameter count for str_replace() in c:FoxServwwwerrorhandlingerror1.php on line 8 The error occurred because str_replace requires a third parameter for the function. The third parameter is the variable, $string_variable, or a string of text in which you want to search for the first parameter, Worx, and replace it with Wrox. Because this is a non-fatal error that does not halt script execution, you can still run code after the point where the error occurred. If you change the snippet to this: The string will continue to execute after the error, and will produce the following output: Warning: Wrong parameter count for str_replace() in c:FoxServwwwerrorhandlingerror1.php on line 8 Worx books are great! Next, we throw out a fatal error to show you how it produces different results when the error occurs. Let s create a fatal error by using the following code: This produces the following output: Beginning Fatal error: Call to undefined function: fatalerror() in c:FoxServwwwerrorhandlingerror2.php on line 10. 262 Chapter 9
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

Michigan web site - Error Integer Value NAMED CONSTANT E_CORE_WARNINGS 32 Non-fatal

Thursday, August 30th, 2007

Error Integer Value NAMED CONSTANT E_CORE_WARNINGS 32 Non-fatal runtime error caused by initial startup. E_COMPILE_WARNING 128 Non-fatal compile-time error. E_USER_ERROR 256 User-generated error by PHP function trigger_error(). E_USER_WARNING 512 User-generated warning by PHP function trigger_error(). E_USER_NOTICE 1024 User-generated notice by PHP function trigger_error(). E_ALL 2047 All errors and warnings reported. E_STRICT 2048 Run-time notices. When enabled, will suggest changes to your code to ensure forward compatibility. Typically, you don t have to worry about all of the error types; your main concern is with runtime errors such as notices, warnings, and errors, along with the user-generated equivalents. The simple, more trivial errors, such as warnings, aren t useful to users or yourself, since they simply notify you that you forgot to initialize a variable or something similar. Because initializing variables is purely for your benefit while you are coding to track down errors before your Web site launch, it is of no use to display these errors to users once your Web site goes live. Your error-handling code helps resolve these cryptic errors to offer helpful, user-friendly messages. The three main types of errors discussed in full here are: . Fatal errors: Fatal runtime errors. These indicate errors that the program can t recover from. Script execution is halted. . Warnings: Runtime warnings (non-fatal errors). Script execution is not halted. . Notices: Runtime notices. These indicate that the script has encountered something that could indicate an error, but could also happen in the normal course of running the script. Generating PHP Errors Now let s generate some errors so that you can check out what you need to do to resolve them. Consider this code snippet, for example: 261 Handling and Avoiding Errors
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

How It Works (Web design rates) The output that you see

Wednesday, August 29th, 2007

How It Works The output that you see in the browser will be the same as you saw before, but behind the scenes, the mail() function is used to send an e-mail to the administrator. Some other PHP functions, such as getdate(), are used to note the time and day the error occurred. The mail() function allows you to e-mail anyone you desire when an error occurs. You will learn about the mail() function in more detail in Chapter 11. Also, by using getdate(), you are able to retrieve when exactly the error occurred so you can make note of the error s time of occurrence. You can get the date in many ways, including the date() function, but the getdate() function is a little easier to decipher. We threw in some function practice for you to get the hang of sending variables as parameters to and from functions. Now the administrator or Webmaster will be getting an HTML-formatted e-mail concerning the error message that the user received when he or she happened to go to that page. That s it! You just used Apache s ErrorDocument directive to help you maintain your server. Error Handling and Creating Error Handling Pages with PHP This section looks at how you can troubleshoot your PHP scripts using simple logical steps. First, however, you need to understand what PHP does when it encounters an error and what it does with certain errors. When a PHP script gets executed and encounters an error, it displays a message in the browser showing you what the error was. Depending on what type of error occurred, the script may not finish executing. You are likely to run into these sorts of errors when writing your own scripts. Don t feel ashamed if you receive errors; everybody makes errors when writing code, no matter what your level of expertise. Even though it is normal to receive errors during the development of your script, you don t want errors (which are normally complicated for the layperson to understand) popping up to end users when your site has gone live. For this reason, it s important to know how to catch those unwanted errors and generate more user-friendly errors that let the user know that there will be a solution forthcoming. Error Types in PHP There are 12 types of errors in PHP, which are listed in the following table, along with the Report All Errors option. Each of these can be called by either an integer value or a named constant. Slight changes have been made as of PHP5: the addition of E_STRICT, and that E_ALL does not include E_STRICT. Error Integer Value NAMED CONSTANT E_ERROR 1 Fatal runtime error. E_WARNING 2 Non-fatal runtime error. E_PARSE 4 Compile-time parse error. E_NOTICE 8 Non-fatal runtime notice. E_CORE_ERROR 16 Fatal error occurring at startup. 260 Chapter 9
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Top ten web hosting - $request_page); break; case 404: $error_output = Page Not

Tuesday, August 28th, 2007

$request_page); break; case 404: $error_output =

Page Not Found Error Page - . (Error Code 404)

; $error_output .= The page you are looking for . cannot be found
; $error_output .= . Contact the system administrator ; $error_output .= if you feel this to be in error ; email_admin($error_no, $error_output, $full_date, $full_time, $request_page); break; case 500: $error_output =

Internal Server Error Error Page - . (Error Code 500)

; $error_output .= The server has encountered . an internal error
; $error_output .= . Contact the system administrator ; $error_output .= if you feel this to be in error ; email_admin($error_no, $error_output, $full_date, $full_time, $request_page); break; default: $error_output =

Error Page

; $error_output .= This is the custom error Page
; $error_output .= You should be here ; } ?> 259 Handling and Avoiding Errors
From our experience, we can recommend PHP Web Hosting services, if you need affordable webhost to host and run your web application.

Web design rates - $full_time = $date[ hours ] . : . $date[ minutes ] .

Monday, August 27th, 2007

$full_time = $date[ hours ] . : . $date[ minutes ] . : . $date[ seconds ] . : . $date[ year ]; $error_no = $_SERVER[ QUERY_STRING ]; $request_page = $_SERVER[ REQUEST_URI ]; switch ($error_no) { case 400: $error_output =

Bad Request Error Page - . (Error Code 400)

; $error_output .= The browser has made a Bad Request
; $error_output .= . Contact the system administrator ; $error_output .= if you feel this to be in error ; email_admin($error_no, $error_output, $full_date, $full_time, $request_page); break; case 401: $error_output =

Authorization Required Error Page - . (Error Code 401)

; $error_output .= You have supplied the wrong information to . access a secure area
; $error_output .= . Contact the system administrator ; $error_output .= if you feel this to be in error ; email_admin($error_no, $error_output, $full_date, $full_time, $request_page); break; case 403: $error_output =

Forbidden Access Error Page - . (Error Code 403)

; $error_output .= You are denied access to this area
; $error_output .= . Contact the system administrator ; $error_output .= if you feel this to be in error ; email_admin($error_no, $error_output, $full_date, $full_time, 258 Chapter 9
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

Web hosting reseller - Figure 9-2 How It Works You have just

Saturday, August 25th, 2007

Figure 9-2 How It Works You have just created a simple error handling PHP page. You created a PHP page that will handle the most common errors that servers encounter. By using the query string information along with the switch() statement, you are able to display custom error message pertinent to the error itself. This is useful if you don t want Apache to display its somewhat cryptic-looking error message to your users. Apache s ErrorDocument: Advanced Custom Error Page Up until this point, you ve been showing the user a custom error message only. You can do countless other things, such as e-mailing the administrator or Webmaster of the site so he or she can look into the issue further should there be a problem with certain pages. This is a great way for you to keep track of your pages without having to check up on the server periodically. More than likely, if you haven t received any error e-mails, there haven t been problems with your server. 256 Chapter 9
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Figure 9-1 (Web server logs) 4. Another way to test or

Friday, August 24th, 2007

Figure 9-1 4. Another way to test or simulate the error messages so that you can ensure you coded the page correctly is to supply the page with the query string information via the browser. For example, to simulate an Internal Server Error error message, type http://localhost/error.php?500 into your address bar. The page will use the query string information and run the code just as if there were an Internal Server Error on one of your pages. The result will look pretty similar to the previous example but will contain a different message. The Internal Server Error page will look like the one shown in Figure 9-2, displaying the Internal Server Error message on the screen. 255 Handling and Avoiding Errors
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.

Frontpage web hosting - Contact the system administrator ; $error_output .= if

Thursday, August 23rd, 2007

Contact the system administrator ; $error_output .= if you feel this to be in error ; break; case 403: $error_output =

"Forbidden Access" Error Page - . (Error Code 403)

; $error_output .= You are denied access to this area
; $error_output .= . Contact the system administrator ; $error_output .= if you feel this to be in error ; break; case 404: $error_output =

"Page Not Found" Error Page - . (Error Code 404)

; $error_output .= The page you are looking for cannot . be found
; $error_output .= . Contact the system administrator ; $error_output .= if you feel this to be in error ; break; case 500: $error_output =

"Internal Server Error" . Error Page (Error Code 500)

; $error_output .= The server has encountered an internal . error
; $error_output .= . Contact the system administrator ; $error_output .= if you feel this to be in error ; break; default: $error_output =

Error Page

; $error_output .= This is the custom error Page
; $error_output .= You should be here ; } ?> 3. Open your browser and type http://localhost/asdf/qwerty/page.html, or any other page you know for certain doesn t reside on your server, into the address bar. You should see the Page Not Found message on the screen, similar to the message shown in Figure 9-1. 254 Chapter 9
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.

Web hosting - message through to the user that there has

Wednesday, August 22nd, 2007

message through to the user that there has been a problem. You can do that with any and all error messages that the server can encounter. Many ErrorDocument codes exist, but we will focus on the error messages you see typically in everyday Web browsing: . 400: Bad Request . 401: Authorization Required . 403: Forbidden . 404: Not Found . 500: Internal Server Error Numerous other error codes exist, of course. You can find a complete list at www.apache.org. Although you are seeing just a few error codes in this exercise, you can catch others as well by simply adding another ErrorDocument to the httpd.conf file. For example, if you want to implement the 501 error code, you would simply add ErrorDocument 501 /error.php?501 to your code and add the error handling in the error.php page, which you ll see shortly. Next, you ll see a simple way to show the user error messages, and then get into some more complex ways to notify the Webmaster of errors occurring on the Web site by using the mail() command that you learned previously. Try It Out Displaying Custom Error Messages To show the user error messages, follow these steps: 1. Open your text editor and save a page called error.php. 2. Enter the following code:

"Bad Request" Error Page - . (Error Code 400)

; $error_output .= The browser has made a Bad Request
; $error_output .= . Contact the system administrator ; $error_output .= if you feel this to be in error ; break; case 401: $error_output =

"Authorization Required" . Error Page - (Error Code 401)

; $error_output .= You have supplied the wrong information to . access a secure area
; $error_output .= . 253 Handling and Avoiding Errors
Check
Tomcat Web Hosting services for best quality webspace to host your web application.