introduction & overview introduction to php - fort collins, co copyright © xtr systems, llc...

27
Introduction & Overview Introduction to PHP - Fort Collins, CO Copyright © XTR Systems, LLC Introduction to & Overview of PHP Instructor: Joseph DiVerdi, Ph.D., MBA

Upload: arlene-page

Post on 13-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

Introduction to& Overview of

PHP

Instructor: Joseph DiVerdi, Ph.D., MBA

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

PHP In Brief

• PHP is a– Server-Side, HTML-embedded, Cross-platform

Scripting Language– Provides a Means for Developers to Put

Instructions in HTML Files to Create Dynamic Content

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

Dynamic Content Example

• Web Clock

Changes from one viewing to another

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

Dynamic Content Example

• Simple Survey

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

Dynamic Content Example

• Simple Game

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

Dynamic Content Example

• Quiz

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

Dynamic Content Example

• Database access

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

Explanations

• Server-Side– PHP Code is Executed on the Server

• HTML-Embedded– PHP Code is Inserted Directly in HTML

• Cross-Platform– PHP Runs on Several Different (Server) OSes

• Scripting Language– Difference Between Scripting & Programming

Languages is Increasingly Small• More Semantic than Significant

– Script is Not Compiled

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

PHP in Less Brief

• PHP Provides a Means for Developers– To Put Instructions in HTML Files– The Instructions are Read & Parsed by Server

• They Never Make It to the Browser

– The Server Replaces PHP Code with Content• HTML etc.

– Forerunner Technology is• Server Side Includes (SSI)

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

Server Side Includes

• Directives Placed Into HTML Document to– Execute Other Programs or – Emit Data Such As Environment Variables

• As With PHP:– The Result is Still an HTML Page– Viewer's Browser Just Sees HTML– SSI Interaction is "behind the scenes"

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

Server Side Includes

• Operation is as Follows:– Client Requests a Document– Server Retrieves Document– Server Recognizes That Document Contains SSI

• Requires ".shtml" suffix– Or Other as Set Up by Webmaster

– Server Parses Document– Server Replaces SSI With Requested Data– Server Returns Document to Client – Client Renders Document

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

Standard HTTP Interaction

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

SSI Interaction

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

SSI Environment Variables

<HTML>

<HEAD>

<TITLE>Welcome!</TITLE>

</HEAD>

<BODY>

Greetings from <!--#echo var="SERVER_NAME"-->

Dear user from <!--#echo var="REMOTE_HOST"-->,

<!-- more HTML goes here... -->

</BODY>

</HTML>

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

SSI External Program Access

<HTML>

<HEAD>

<TITLE>Welcome!</TITLE>

</HEAD>

<BODY>

Greetings from <!--#echo var="SERVER_NAME"-->

Dear user from <!--#echo var="REMOTE_HOST"-->,

The current time is <!--#exec cmd="date"--><BR>

<!-- more HTML goes here... -->

</BODY>

</HTML>

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

SSI Include

<HTML>

<HEAD>

<TITLE>Welcome!</TITLE>

</HEAD>

<BODY>

Greetings from <!--#echo var="SERVER_NAME"-->

Dear user from <!--#echo var="REMOTE_HOST"-->,

The current time is <!--#exec cmd="date"--><BR>

<!-- more HTML goes here... -->

<!--#include virtual=navigation_bar.html-->

</BODY>

</HTML>

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

Server Side Includes

• SSI is a Great Tool– Adds Dynamic Content

• Date, Last Modified, etc.

– Relatively Simple to Use– Eases Development

• #include file="footer.html"

– Sophisticated Tool• Hide links from external users

<!--#if expr="$REMOTE_ADDR = /^1.2.3./" -->

<a href="internal-documents.html">Internal Documents</a>

<!--#endif -->• Where 1.2.3 is the IP address prefix of the local domain

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

Server Side Includes

• There are Serious Disadvantages:– No Official Standard

• Web Server is Free to Support Different Commands• Many Commands Are De Facto Standards

– #include, #echo, #exec

– Costly for Server to Parse Documents• SSI Isn't Very Efficient to Execute• Each SSI Program on a Page

– Launches a Separate Process

– Doubles the Server Load for Viewing That Page

– Significant Security Risk• Too Easy to Allow Commands to Be Executed on Server

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

Other Developments

• Need for HTML-Embedded Server-Side Scripting Technology was Apparent to Others

• Microsoft went after this need with ASP – Active Server Pages

• ASP Has Become Quite Popular– In Microsoft Shops

• Many Developers Sought More Stable & Less Proprietary Solution– Enter PHP, an Open-Source Server-Parsed

HTML-Embedded Scripting Language

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

PHP Benefits

• PHP's Primary Strength– Rapid Development of Dynamic Web Pages

• Developers Without Heavy Programming Experience– Leverage PHP to Complete Tasks otherwise

cryptic or obtuse in alternative languages• Pulling Records From a Database & • Inserting Them Into an HTML Table

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

PHP Benefits

• PHP Language Architecture– Simple but Powerful– Includes an Extremely Wide Variety of Functions

• Suited for Many Tasks– Traditional Data Processing

– Web-Oriented Functions

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

PHP Example

<HTML>

<HEAD>

<TITLE>Welcome!</TITLE>

</HEAD>

<BODY>

<?PHP phpinfo() ?>

<!-- more HTML goes here... -->

</BODY>

</HTML>

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

PHP Weaknesses

• PHP Remains an Immature Language– Without the Architectural Strengths or Extensibility

of More Established Languages

• Embedded Scripting– Program Code is Mixed With HTML

• Some Developers Are Empowered By This• Others Find It Disorganized & Error-Prone

– Prefer Separate Development Environments• For Each Web Component

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

PHP Weaknesses

• Developers with Experience in Perl & Especially mod_perl Environments – May Find Little Reason to Spend Time with PHP– And This May be Entirely Justified

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

PHP Strengths

• Developers have literally flocked to PHP– Modest Learning Curve– Free & Open Development– Native Database Connectivity– Stability– Availability for a Variety of Server Platforms

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

• Still, it is Important to Understand That PHP is not a Unique Solution to Web Development– We're Fortunate to Enjoy a Potpourri of Possible

Web Development Tools

• Many Tasks can be Performed with a Wide Variety of Technologies– Developers Must Weigh Many Factors in

Choosing a Development Path• Previous & Current Experience• Platform Requirements & Support• Time-to-Market Requirements

Introduction & OverviewIntroduction to PHP - Fort Collins, CO

Copyright © XTR Systems, LLC

PHP Example

<HTML>

<HEAD>

<TITLE>PHP Test Page</TITLE>

</HEAD>

<BODY>

<?PHP phpinfo() ?>

<!-- more HTML goes here... -->

</BODY>

</HTML>

• Create page on linus named "test.php"