58Part IPHP: The BasicsThey are called from a (Free web hosts)

58Part IPHP: The BasicsThey are called from a PHP page this way:

This is some body text for this particular page.

Obviously, this single move greatly enhances the maintainability and scalability of an entiresite. Now, if you want a different look and feel or if you need to update the copyright notice, you can alter one file instead of identical lines in dozens of HTML pages. When including files, remember to set the include_pathdirective correctly in yourphp.inifile. Remember that you can include files from above or entirely outside your Webtree by proper use of this directive. See Chapter 30 for more information. As you can see from the preceding example, PHP s includefunctions simply pass along thecontents of the included file as text. Many people think that because an includefunctionoccurs inside PHP mode, the included file will also be in PHP mode. This is not true! Actually, the server escapes back into HTML mode at the beginning of each included file and silentlyreturns to PHP mode at the end, just in time to catch the semicolon. As always, you need to say when you intend something to be PHP by using PHP opening andclosing tags. Any part of an included file that needs to be executed as PHP should beenclosed in valid PHP tags. If the entire file is PHP (very common in files of functions), theentire file must be enclosed within PHP tags. Take the following file, database.inc: $db = mysql_connect( localhost , db_user , db_password ); mysql_select_db( my_database ); We can t emphasize this enough: If you re having problems including PHP files, particularly ifyou re seeing output you don t expect or not seeing output you do expect, be ABSOLUTELYPOSITIVEthat you ve put PHP tags at the beginning and end of the included file. If you were to foolishly include this file from a PHP script, your database variables would bevisible to the world in plain text because you neglected to use PHP tags, the parser assumesthis block of code is HTML. A correct version of the database.incfile would look like this: For all PHP files included from other files, you must ensure that there are no empty new linesat the end of the file. Remember, anything outside a PHP block is considered HTML, even ablank line. Blank lines, or even blank spaces outside a closing PHP tag, will be interpreted asoutput. If you include the file in a situation where you cannot have output say before usingHTTP headers your script will fail with a big error message about the output stream havingalready been started in your included file. See Chapter 11 for an example. CautionCautionTip06
Note: In case you are looking for affordable webhost to host and run your servlet application check Vision ecommerce web hosting services

Leave a Reply