1. Trang chủ
  2. » Công Nghệ Thông Tin

PHP 5/MySQL Programming- P8 ppt

5 1,6K 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 5
Dung lượng 122,2 KB

Nội dung

A PHP program looks a lot like a typical HTML page. The difference is the special <? ?> tag, which specifies the existence of PHP code. Any code inside the tag is read by the PHP interpreter and then converted into HTML code. The code written between the <? and ?> symbols is PHP code. I added two commands to the page. Look at the output of the program shown in Figure 1.4. You might be surprised. Examining the Results This page has three distinct types of text. • Hello in PHP is ordinary HTML. I wrote it just like a regular HTML page, and it was displayed just like regular HTML. • Hello, world! was written by the PHP program embedded in the page. • The rest of the page is a bit mysterious. It contains a lot of information about the particular PHP engine being used. It actually stretches on for several pages. The phpInfo() command generated all that code. This command displays information about the PHP installation. It isn’t that important to understand all the information displayed by the phpInfo() command. It’s much more critical to appreciate that when the user requests the hello.html Web page, the text is first run through the PHP inter- preter. This program scans for any PHP commands, executes them, and prints HTML code in place of the original commands. All the PHP code is gone by the time a page gets to the user. 13 C h a p t e r 1 E x p l o r i n g t h e P H P E n v i r o n m e n t FIGURE 1.4 The page mixes HTML with some other things. For proof of this, point your browser at hello.php and view the source code. It looks something like this: <html> <head> <title>Hello in PHP</title> </head> <body> <h1>Hello in PHP</h1> Hello, world!<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”> <html> <head><style type=”text/css”><!— a { text-decoration: none; } a:hover { text-decoration: underline; } h1 { font-family: arial, helvetica, sans-serif; font-size: 18pt; font- weight: bold;} h2 { font-family: arial, helvetica, sans-serif; font-size: 14pt; font- weight: bold;} body, td { font-family: arial, helvetica, sans-serif; font-size: 10pt; } th { font-family: arial, helvetica, sans-serif; font-size: 11pt; font-weight: bold; } //—></style> <title>phpinfo()</title></head><body><table border=”0” cellpadding=”3” cellspacing=”1” width=”600” bgcolor=”#000000” align=”center”> <tr valign=”middle” bgcolor=”#9999cc”><td align=”left”> <a href=”http://www.php.net/”><img src=”/phab/ph01/hello.php?=PHPE9568F34- D428-11d2-A769-00AA001ACF42” border=0 align=”right” alt=”PHP Logo”></a> <h1>PHP Version 4.2.1</h1> Note that I showed only a small part of the code generated by the phpInfo() com- mand. Also, note that the code details might be different when you run the pro- gram on your own machine. The key point is that the PHP code that writes Hello, World! (print “Hello, World!”) is replaced with the actual text Hello, World! More significantly, a huge amount of HTML code replaces the very simple phpInfo() command. A small amount of PHP code can very efficiently generate large and complex HTML documents. This is one significant advantage of PHP. Also, by the time the document gets to the Web browser, it’s plain-vanilla HTML code, which can be 14 P H P 5 /M y S Q L P r o g r a m m i n g f o r t h e A b s o l u t e B e g i n n e r read easily by any browser. These two features are important benefits of server- side programming in general, and of PHP programming in particular. As you progress through this book, you learn about many more commands for producing interesting HTML, but the basic concept is always the same. Your PHP program is simply an HTML page that contains special PHP markup. The PHP code is examined by a special program on the server. The results are embedded into the Web page before it is sent to the user. Configuring Your Version of PHP If you’re running your own server, you probably want to tweak your version of PHP so it works cleanly. I have a number of suggestions for configuration that provide a relatively friendly environment for beginning programs. In particular, think about the following elements. Safe Mode This mode is a master setting that allows you to choose between ease of program- ming and server safety. For beginners, I recommend setting safe-mode to OFF while working on your own Web server. As you move to a production server, you will usually have safe mode set to ON, which requires you to be a little more care- ful about some elements. (However, most of these are advanced settings you won’t need to worry about yet. The most important reason to have safe mode off right now is to allow access to the register_globals directive that is described next.) Register Globals The register_globals parameter determines whether PHP automatically trans- fers information from web forms to your program. (It’s okay if that doesn’t mean much to you yet.) This feature is useful for beginning programmers, but can be a security risk. As you get more comfortable (after chapter 5, when I show you some alternatives to register_globals) you can turn off this variable to protect your code from some potential problems. To change this variable’s value, simply type on or off as the value for register globals. As with any change to php.ini, restart your Web server to ensure the changes have taken hold. Search in php.ini for a line that looks like this: register_globals = On 15 C h a p t e r 1 E x p l o r i n g t h e P H P E n v i r o n m e n t Windows Extensions PHP comes with a number of extensions that allow you to modify its behavior. You can add functionality to your copy of PHP by adding new modules. To find the part of php.ini that describes these extensions, look for windows extensions in the php.ini file. You’ll see some code that looks like this: ;Windows Extensions ;extension=php_bz2.dll ;extension=php_ctype.dll ;extension=php_cpdf.dll ;extension=php_curl.dll ;extension=php_cybercash.dll ;extension=php_db.dll ;extension=php_dba.dll ;extension=php_dbase.dll ;extension=php_dbx.dll ;extension=php_domxml.dll ;extension=php_dotnet.dll ;extension=php_exif.dll ;extension=php_fbsql.dll ;extension=php_fdf.dll ;extension=php_filepro.dll ;extension=php_gd.dll ;extension=php_gettext.dll ;extension=php_hyperwave.dll ;extension=php_iconv.dll ;extension=php_ifx.dll ;extension=php_iisfunc.dll ;extension=php_imap.dll ;extension=php_ingres.dll ;extension=php_interbase.dll ;extension=php_java.dll ;extension=php_ldap.dll ;extension=php_mbstring.dll ;extension=php_mcrypt.dll ;extension=php_mhash.dll ;extension=php_mssql.dll 16 P H P 5 /M y S Q L P r o g r a m m i n g f o r t h e A b s o l u t e B e g i n n e r ;extension=php_oci8.dll ;extension=php_openssl.dll ;extension=php_oracle.dll ;extension=php_pdf.dll ;extension=php_pgsql.dll ;extension=php_printer.dll ;extension=php_sablot.dll ;extension=php_shmop.dll ;extension=php_snmp.dll ;extension=php_sockets.dll ;extension=php_sybase_ct.dll ;extension=php_xslt.dll ;extension=php_yaz.dll ;extension=php_zlib.dll ;;;;; I added gd2 extension extension=php_gd2.dll ;;; I added ming support extension=php_ming.dll ;;;;;I added mysql extension extension=php_mysql.dll The php.ini file that comes with PHP 5.0 has a note that says mySQL support is built in. I found this was not the case in my installation. Run the phpInfo() command (in the Hello.php program described earlier, for example) to see exactly which extensions are active in your installation. If you don’t see an exten- sion that you need, you can add it yourself. Most of the extensions begin with a semicolon. This character acts like a com- ment character and causes the line to be ignored. To add a particular extension, simply eliminate the semicolon at the beginning of the line. I usually put a com- ment in the code to remind myself that I added this extension. I added the php_mysql.dll extension. This allows support for the MySQL database language used in the second half of this book. Add support for that library by removing the semicolon characters from the beginning of the mysql line. TRAP 17 C h a p t e r 1 E x p l o r i n g t h e P H P E n v i r o n m e n t . Extensions ;extension =php_ bz2.dll ;extension =php_ ctype.dll ;extension =php_ cpdf.dll ;extension =php_ curl.dll ;extension =php_ cybercash.dll ;extension =php_ db.dll ;extension =php_ dba.dll ;extension =php_ dbase.dll ;extension =php_ dbx.dll ;extension =php_ domxml.dll ;extension =php_ dotnet.dll ;extension =php_ exif.dll ;extension =php_ fbsql.dll ;extension =php_ fdf.dll ;extension =php_ filepro.dll ;extension =php_ gd.dll ;extension =php_ gettext.dll ;extension =php_ hyperwave.dll ;extension =php_ iconv.dll ;extension =php_ ifx.dll ;extension =php_ iisfunc.dll ;extension =php_ imap.dll ;extension =php_ ingres.dll ;extension =php_ interbase.dll ;extension =php_ java.dll ;extension =php_ ldap.dll ;extension =php_ mbstring.dll ;extension =php_ mcrypt.dll ;extension =php_ mhash.dll ;extension =php_ mssql.dll 16 P H P 5 /M y S Q L P r o g r a m m i n g f o r t h e A b s o l u t e B e g i n n e r ;extension =php_ oci8.dll ;extension =php_ openssl.dll ;extension =php_ oracle.dll ;extension =php_ pdf.dll ;extension =php_ pgsql.dll ;extension =php_ printer.dll ;extension =php_ sablot.dll ;extension =php_ shmop.dll ;extension =php_ snmp.dll ;extension =php_ sockets.dll ;extension =php_ sybase_ct.dll ;extension =php_ xslt.dll ;extension =php_ yaz.dll ;extension =php_ zlib.dll ;;;;;. Extensions ;extension =php_ bz2.dll ;extension =php_ ctype.dll ;extension =php_ cpdf.dll ;extension =php_ curl.dll ;extension =php_ cybercash.dll ;extension =php_ db.dll ;extension =php_ dba.dll ;extension =php_ dbase.dll ;extension =php_ dbx.dll ;extension =php_ domxml.dll ;extension =php_ dotnet.dll ;extension =php_ exif.dll ;extension =php_ fbsql.dll ;extension =php_ fdf.dll ;extension =php_ filepro.dll ;extension =php_ gd.dll ;extension =php_ gettext.dll ;extension =php_ hyperwave.dll ;extension =php_ iconv.dll ;extension =php_ ifx.dll ;extension =php_ iisfunc.dll ;extension =php_ imap.dll ;extension =php_ ingres.dll ;extension =php_ interbase.dll ;extension =php_ java.dll ;extension =php_ ldap.dll ;extension =php_ mbstring.dll ;extension =php_ mcrypt.dll ;extension =php_ mhash.dll ;extension =php_ mssql.dll 16 P H P 5 /M y S Q L P r o g r a m m i n g f o r t h e A b s o l u t e B e g i n n e r ;extension =php_ oci8.dll ;extension =php_ openssl.dll ;extension =php_ oracle.dll ;extension =php_ pdf.dll ;extension =php_ pgsql.dll ;extension =php_ printer.dll ;extension =php_ sablot.dll ;extension =php_ shmop.dll ;extension =php_ snmp.dll ;extension =php_ sockets.dll ;extension =php_ sybase_ct.dll ;extension =php_ xslt.dll ;extension =php_ yaz.dll ;extension =php_ zlib.dll ;;;;;. Extensions ;extension =php_ bz2.dll ;extension =php_ ctype.dll ;extension =php_ cpdf.dll ;extension =php_ curl.dll ;extension =php_ cybercash.dll ;extension =php_ db.dll ;extension =php_ dba.dll ;extension =php_ dbase.dll ;extension =php_ dbx.dll ;extension =php_ domxml.dll ;extension =php_ dotnet.dll ;extension =php_ exif.dll ;extension =php_ fbsql.dll ;extension =php_ fdf.dll ;extension =php_ filepro.dll ;extension =php_ gd.dll ;extension =php_ gettext.dll ;extension =php_ hyperwave.dll ;extension =php_ iconv.dll ;extension =php_ ifx.dll ;extension =php_ iisfunc.dll ;extension =php_ imap.dll ;extension =php_ ingres.dll ;extension =php_ interbase.dll ;extension =php_ java.dll ;extension =php_ ldap.dll ;extension =php_ mbstring.dll ;extension =php_ mcrypt.dll ;extension =php_ mhash.dll ;extension =php_ mssql.dll 16 P H P 5 /M y S Q L P r o g r a m m i n g f o r t h e A b s o l u t e B e g i n n e r ;extension =php_ oci8.dll ;extension =php_ openssl.dll ;extension =php_ oracle.dll ;extension =php_ pdf.dll ;extension =php_ pgsql.dll ;extension =php_ printer.dll ;extension =php_ sablot.dll ;extension =php_ shmop.dll ;extension =php_ snmp.dll ;extension =php_ sockets.dll ;extension =php_ sybase_ct.dll ;extension =php_ xslt.dll ;extension =php_ yaz.dll ;extension =php_ zlib.dll ;;;;;

Ngày đăng: 07/07/2014, 02:20

TỪ KHÓA LIÊN QUAN