PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

22
PHP: Hypertext PHP: Hypertext Preprocessor Preprocessor Greg Lowe Greg Lowe Rob White Rob White Brian Wright Brian Wright Mike Zywiec Mike Zywiec
  • date post

    15-Jan-2016
  • Category

    Documents

  • view

    222
  • download

    0

Transcript of PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

Page 1: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

PHP: Hypertext PHP: Hypertext PreprocessorPreprocessor

Greg LoweGreg LoweRob WhiteRob White

Brian WrightBrian WrightMike Zywiec Mike Zywiec

Page 2: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

IntroductionIntroduction

PHP stands for “PHP: Hypertext PHP stands for “PHP: Hypertext Preprocessor”Preprocessor”

Server-side scripting languageServer-side scripting language

Syntactically similar to CSyntactically similar to C

Utilized by approximately 33% of web Utilized by approximately 33% of web domains on the webdomains on the web

Page 3: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

HistoryHistory

1995 – Rasmus Lerdorf wrote the Personal 1995 – Rasmus Lerdorf wrote the Personal Home Page/Form Interpreter: PHP/FIHome Page/Form Interpreter: PHP/FIWanted to create a HTML-centric language as Wanted to create a HTML-centric language as opposed to PERL which was PERL-centricopposed to PERL which was PERL-centricCode was inside the HTML document and Code was inside the HTML document and written within <!-- --> Tagswritten within <!-- --> TagsExample: Example:

<!--getenv HTTP_USER_AGENT--><!--getenv HTTP_USER_AGENT--><!—ifsubstr $exec_result Mozilla--> <!—ifsubstr $exec_result Mozilla--> Hey, you are using Netscape!<p> Hey, you are using Netscape!<p> <!--endif--> <!--endif-->

Page 4: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

HistoryHistory

Lerdorf was not satisfied with PHP/FI so Lerdorf was not satisfied with PHP/FI so he wrote PHP/FI v.2he wrote PHP/FI v.2

Embedded commands within <? > tagsEmbedded commands within <? > tags

Same syntax used todaySame syntax used today

Page 5: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

HistoryHistory

1997—Zeev Suraski and Andi Gutmans 1997—Zeev Suraski and Andi Gutmans contacted Lerdorf in an effort to combine their contacted Lerdorf in an effort to combine their already written engine with PHP/FI v.2already written engine with PHP/FI v.2After agreeing, the three and some others After agreeing, the three and some others finished the release of PHP v.3finished the release of PHP v.3PHP v.3 gained:PHP v.3 gained: Limited Object Oriented SupportLimited Object Oriented Support More speedMore speed Numerous DB support (MySQL, ODBC, Oracle, …)Numerous DB support (MySQL, ODBC, Oracle, …) ExtensibilityExtensibility

Allowed for programmers to write their own modules for the Allowed for programmers to write their own modules for the language language

Page 6: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

HistoryHistory

Zeev and Andy went to work on what is Zeev and Andy went to work on what is now called the Zend Enginenow called the Zend Engine

The Zend Engine + PHP v3 = PHP4(2000)The Zend Engine + PHP v3 = PHP4(2000)

Page 7: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

HistoryHistory

PHP v. 5 -- 2004PHP v. 5 -- 2004 Better Objected Oriented SupportBetter Objected Oriented Support Better Error CheckingBetter Error Checking

Java Style try{} catch{}Java Style try{} catch{} SimpleXML SimpleXML

Easy interaction with XML DocumentsEasy interaction with XML Documents

Page 8: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

Installing PHPInstalling PHP

Web EnvironmentWeb Environment

Command Line InterfaceCommand Line Interface

Page 9: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

Command Line PHP ScriptingCommand Line PHP Scripting

Can execute code from command line in Can execute code from command line in three ways:three ways: Executing fileExecuting file Code from command lineCode from command line Passed code from standard inputPassed code from standard input

Page 10: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

Advantages of CLI InstallationAdvantages of CLI Installation

Same code can work on Unix or Windows Same code can work on Unix or Windows machinesmachines ‘‘#!/usr/bin/php’#!/usr/bin/php’

Web-independent developmentWeb-independent development

Page 11: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

For Server-Side ScriptingFor Server-Side Scripting

Prepackaged solutionsPrepackaged solutions

Manually compiling & configuring Manually compiling & configuring

Works for Apache 1.3.x/2.0, IISWorks for Apache 1.3.x/2.0, IIS

Page 12: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

Known IssuesKnown Issues

IISIIS Delicacy (Security)Delicacy (Security)

Apache Apache 2.0 (Thread safety, high-traffic areas)2.0 (Thread safety, high-traffic areas)

Page 13: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

PHP Strengths:PHP Strengths:

Ready to use tools to interface with many Ready to use tools to interface with many databases and web utilities. (MySQL, databases and web utilities. (MySQL, Oracle, Etc.) Oracle, Etc.)

Easily extensible. PHP is modular and it is Easily extensible. PHP is modular and it is simple to create utilities to extend the simple to create utilities to extend the capabilities of the language. capabilities of the language.

PEAR project (PEAR project (http://http://pear.php.netpear.php.net) )

Page 14: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

PHP Strengths:PHP Strengths:

Server Side processing Server Side processing

No client side software No client side software

Page 15: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

PHP Weaknesses:PHP Weaknesses:

Weakly typed variables. Weakly typed variables.

Poor error detection / warning. Poor error detection / warning.

Really only suitable for web applications.Really only suitable for web applications.

Page 16: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

PHPPHP<?php <?php

// Print a greeting if the form was submitted // Print a greeting if the form was submitted if ($_POST['user']) { if ($_POST['user']) {

print "Hello, ";print "Hello, "; // Print what was submitted in the form parameter called 'user' // Print what was submitted in the form parameter called 'user' print $_POST['user']; print $_POST['user']; print "!"; print "!";

} else { } else { // Otherwise, print the form // Otherwise, print the form print <<<_HTML_ print <<<_HTML_ <form method="post" action="$_SERVER[PHP_SELF]"> <form method="post" action="$_SERVER[PHP_SELF]"> Your Name: <input type="text" name="user"> Your Name: <input type="text" name="user"> <br/> <br/> <input type="submit" value="Say Hello"><input type="submit" value="Say Hello"></form> _HTML_; </form> _HTML_;

} } ?> ?>

Page 17: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

PHPPHP

<form method="post" action="/~gl1042/PHP/example-1-05.php"> <form method="post" action="/~gl1042/PHP/example-1-05.php">

Your Name: <input type="text" name="user"> Your Name: <input type="text" name="user">

<br/> <br/>

<input type="submit" value="Say Hello"> <input type="submit" value="Say Hello">

</form> </form>

Then when I click on enter the returned information is:Then when I click on enter the returned information is:

Hello, greg!Hello, greg!

Example-1-05.phpExample-1-05.php

Page 18: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

PHPPHPrequire 'DB.php';require 'DB.php';

$db = B::connect('mysql://hunter:w)[email protected]/restaurant');$db = B::connect('mysql://hunter:w)[email protected]/restaurant');

if (DB::isError($db)) if (DB::isError($db)) { {

die("connection error: " . $db->getMessage( )); die("connection error: " . $db->getMessage( )); }}

// Eggplant with Chili Sauce is spicy// Eggplant with Chili Sauce is spicy$db->query("UPDATE dishes SET is_spicy = 1 $db->query("UPDATE dishes SET is_spicy = 1 WHERE dish_name = 'Eggplant with Chili Sauce");WHERE dish_name = 'Eggplant with Chili Sauce");

// Lobster with Chili Sauce is spicy and pricy// Lobster with Chili Sauce is spicy and pricy$db->query("UPDATE dishes SET is_spicy = 1, price=price * 2$db->query("UPDATE dishes SET is_spicy = 1, price=price * 2 WHERE dish_name = 'Lobster with Chili Sauce'"); WHERE dish_name = 'Lobster with Chili Sauce'");

Page 19: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

PHPPHP

<?php<?php

print 'strftime() says: ';print 'strftime() says: ';

print strftime('%c');print strftime('%c');

print "\n";print "\n";

print 'date() says:';print 'date() says:';

print date('r');print date('r');

?>?>

1example-9-011example-9-01

Page 20: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

PHPPHP

<?php<?phpfunction page_header2($color) {function page_header2($color) { print '<html><head><title>Welcome to my print '<html><head><title>Welcome to my

site</title></head>';site</title></head>'; print '<body bgcolor="#' . $color . '">';print '<body bgcolor="#' . $color . '">';}}page_header2('cc00cc');}page_header2('cc00cc');}?>?>

1example-5-04.php1example-5-04.php

Page 21: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

PHPPHP

<?php phpinfo(); ?><?php phpinfo(); ?>

Example-A-03.phpExample-A-03.php

Page 22: PHP: Hypertext Preprocessor Greg Lowe Rob White Brian Wright Mike Zywiec.

PHPPHP