220 likes | 317 Views
PHP: Hypertext Preprocessor. Greg Lowe Rob White Brian Wright Mike Zywiec. Introduction. PHP stands for “PHP: Hypertext Preprocessor” Server-side scripting language Syntactically similar to C Utilized by approximately 33% of web domains on the web. History.
E N D
PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec
Introduction • PHP stands for “PHP: Hypertext Preprocessor” • Server-side scripting language • Syntactically similar to C • Utilized by approximately 33% of web domains on the web
History • 1995 – Rasmus Lerdorf wrote the Personal Home Page/Form Interpreter: PHP/FI • Wanted to create a HTML-centric language as opposed to PERL which was PERL-centric • Code was inside the HTML document and written within <!-- --> Tags • Example: <!--getenv HTTP_USER_AGENT--> <!—ifsubstr $exec_result Mozilla--> Hey, you are using Netscape!<p> <!--endif-->
History • Lerdorf was not satisfied with PHP/FI so he wrote PHP/FI v.2 • Embedded commands within <? > tags • Same syntax used today
History • 1997—Zeev Suraski and Andi Gutmans contacted Lerdorf in an effort to combine their already written engine with PHP/FI v.2 • After agreeing, the three and some others finished the release of PHP v.3 • PHP v.3 gained: • Limited Object Oriented Support • More speed • Numerous DB support (MySQL, ODBC, Oracle, …) • Extensibility • Allowed for programmers to write their own modules for the language
History • Zeev and Andy went to work on what is now called the Zend Engine • The Zend Engine + PHP v3 = PHP4(2000)
History • PHP v. 5 -- 2004 • Better Objected Oriented Support • Better Error Checking • Java Style try{} catch{} • SimpleXML • Easy interaction with XML Documents
Installing PHP • Web Environment • Command Line Interface
Command Line PHP Scripting • Can execute code from command line in three ways: • Executing file • Code from command line • Passed code from standard input
Advantages of CLI Installation • Same code can work on Unix or Windows machines • ‘#!/usr/bin/php’ • Web-independent development
For Server-Side Scripting • Prepackaged solutions • Manually compiling & configuring • Works for Apache 1.3.x/2.0, IIS
Known Issues • IIS • Delicacy (Security) • Apache • 2.0 (Thread safety, high-traffic areas)
PHP Strengths: • Ready to use tools to interface with many databases and web utilities. (MySQL, Oracle, Etc.) • Easily extensible. PHP is modular and it is simple to create utilities to extend the capabilities of the language. • PEAR project (http://pear.php.net)
PHP Strengths: • Server Side processing • No client side software
PHP Weaknesses: • Weakly typed variables. • Poor error detection / warning. • Really only suitable for web applications.
PHP <?php // Print a greeting if the form was submitted if ($_POST['user']) { print "Hello, "; // Print what was submitted in the form parameter called 'user' print $_POST['user']; print "!"; } else { // Otherwise, print the form print <<<_HTML_ <form method="post" action="$_SERVER[PHP_SELF]"> Your Name: <input type="text" name="user"> <br/> <input type="submit" value="Say Hello"> </form> _HTML_; } ?>
PHP <form method="post" action="/~gl1042/PHP/example-1-05.php"> Your Name: <input type="text" name="user"> <br/> <input type="submit" value="Say Hello"> </form> Then when I click on enter the returned information is: Hello, greg! Example-1-05.php
PHP require 'DB.php'; $db = B::connect('mysql://hunter:w)blah@example.com/restaurant'); if (DB::isError($db)) { die("connection error: " . $db->getMessage( )); } // Eggplant with Chili Sauce is spicy $db->query("UPDATE dishes SET is_spicy = 1 WHERE dish_name = 'Eggplant with Chili Sauce"); // Lobster with Chili Sauce is spicy and pricy $db->query("UPDATE dishes SET is_spicy = 1, price=price * 2 WHERE dish_name = 'Lobster with Chili Sauce'");
PHP • <?php • print 'strftime() says: '; • print strftime('%c'); • print "\n"; • print 'date() says:'; • print date('r'); • ?> • 1example-9-01
PHP <?php function page_header2($color) { print '<html><head><title>Welcome to my site</title></head>'; print '<body bgcolor="#' . $color . '">'; } page_header2('cc00cc');} ?> 1example-5-04.php
PHP <?php phpinfo(); ?> Example-A-03.php