Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006 Instructor: John...

16
Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006 www.clt.astate.edu/jseydel/mis3353 Instructor: John Seydel, Ph.D.

Transcript of Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006 Instructor: John...

Page 1: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

Website Development & Management

More PHP Fundamentals

CIT 3353 -- Fall 2006www.clt.astate.edu/jseydel/mis3353

Instructor: John Seydel, Ph.D.

Page 2: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

Student Objectives

Upon completion of this class meeting, you should be able to: Apply the recommended process for writing

scripts Summarize the use of several PHP string

functions Use a multi-level if() statement Create pages that send email messages Use the empty() function for testing if

variables have values assigned Use the getenv() function to access PHP

environment variables

Page 3: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

What We Saw Last TimeRudimentary form validation (server-side)String manipulation

Concatenation assignment operator: .= Mixing literals and variables Escape character

PHP functions (refer to Appendix B) header() print() or echo() pow() number_format(value) and

number_format(value,places)

Fairly complex formula (a common business application)General code development and concurrent testing

Page 4: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

Process Guidelines for Writing Scripts

Start by initializing Assign initial values to variables Define constants if any

Get data From form From other sources

Prepare data for processingWrite the processing logic

Branching as appropriate Calculations as appropriate String manipulations as appropriate Other processing (e.g., send mail, write to database, . .

. )

Format results for output as appropriate

Page 5: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

Some Handy Tools: Several String Functions for PHP

These may or may not have practical value right away, so just note that they exist and consider using them at the appropriate time:

Convert number to formatted string: number_format()

Change case To upper: strtoupper() To lower case: strtolower()

Change to title case: ucwords() Determine number of characters: strlen() Reverse characters: strrev() Convert to 32 byte hash: md5() Insert <br /> for every occurrence of \n: n12br()

Refer to examples in Chapter 7Other functions: see Appendix B

Page 6: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

Writing Scripts that Send eMail

Some example applications CIT advising form Online order confirmation

Makes use of the mail() functionString Arguments accepted for mail():

Recipient Subject Message Header

From (overrides value specified in php.ini) Reply-to Other . . .

First, we need to set values in php.ini Example

SMTP = smail.astate.edu (i.e., your ISP ) sendmail_from = [email protected]

Afterwards, restart Apache

Page 7: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

Demonstration: An eMail Application

Add registration capability to the FKAuto homepageGenerates two confirmations Web page eMail message to the prospective customer

Refer to Suzy’s website Handout

Work along as we develop the rest of the code

Page 8: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

eMail Security & Authentication

Impediments to automated emailing Firewall on the web server (e.g., localhost) Mail servers that won’t accept/transmit messages

ASU’s mail servers Limit what scripts can do; won’t

Accept SMTP requests from outside the ASU network Process SMTP requests to addresses outside ASU domain

Apparently process strictly internal SMTP requests SuSE1 Localhost servers on lab machines

What matters is not where the browser is but rather where the web server is

Page 9: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

What We’ve Just Seen

The scripting process for a typical PHP applicationSome new functions getenv() empty() mail()

A more complex if() construct

Page 10: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

Summary of Today’s Objectives

Apply the recommended process for writing scripts

Summarize the use of several PHP string functions

Use a multi-level if() statement Create pages that send email messages Use the empty() function for testing if

variables have values assigned Use the getenv() function to access

PHP environment variables

Page 11: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

Some RemarksModify your own PHP initialization file (c:\WINDOWS\php.ini)

error_reporting = E_ALL & ~E_NOTICE display_errors = On Restart Apache

Naming form controlsTextbook issues (Meloni)

Atrocious HTML Global arrays

Arguments not quoted Use raw without assigning elements to local variables

Note Appendix B, howeverNote some things in the form page (calc.php)

JavaScript Arrays foreach() construct

Page 12: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

Consider Some Enhancements

Replace if() construct with switch() constructCheck for a valid email address Use ereg()

Case-sensitive; use eregi() for case-insensitive Alternative to preg_match(), which is a Perl-

compatible function Search for an asterisk (*) Syntax: ereg($strTo,”*”)

Add onLoad event handler to <body>

Page 13: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

Appendix

Page 14: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

A PHP ApplicationNote the example www.suse1.astate.edu/~ford-j/fki

Monthly payments Inputs

A = Loan n = Term (months) i = Interest (monthly, decimal)

Output: monthly payment (Pmt)Finally, note the use of the term application

No longer simply a web page Instead, an application program with numerous

interdependent components Interface pages

Input Output

Include files Processing units Other important files

Page 15: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

Names to Use for ControlsUse conventions from programming languages: Java, C++, Visual BasicTypically

First 3 characters lowercase and type of control Uppercase only when words joined (intercap)

Control Type Prefix Example

Textbox txt txtFirstName

Text Area txt txtFeedback

Checkbox chk chkRetirement

Option Button opt optClass

Dropdown List lst lstWeekDay

Submit Button cmd cmdCalculatePay

Page 16: Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006  Instructor: John Seydel, Ph.D.

Review: Browser/Server Interaction