Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Website Development & Management More PHP Fundamentals CIT 3353 -- Fall 2006 www.clt.astate.edu/jseydel/mis3353 Instructor: John Seydel, Ph.D."— Presentation transcript:

1

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

3 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

4 What We Saw Last TimeLast Time Rudimentary 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

5 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 processing Write 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

6 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 for every occurrence of \n: n12br() Refer to examples in Chapter 7 Other functions: see Appendix B

7 Writing Scripts that Send eMail Some example applications CIT advising formadvising form Online order confirmationorder confirmation Makes use of the mail() function String 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 = JoJo.Beans@smail.astate.eduJoJo.Beans@smail.astate.edu Afterwards, restart Apache

8 Demonstration: An eMail Application Add registration capability to the FKAuto homepage Generates 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

9 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

10 What We’ve Just Seen The scripting process for a typical PHP applicationprocess Some new functions getenv() empty() mail() A more complex if() construct

11 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

12 Some Remarks Modify your own PHP initialization file (c:\WINDOWS\php.ini) error_reporting = E_ALL & ~E_NOTICE display_errors = On Restart Apache Naming form controlsform controls Textbook issues (Meloni) Atrocious HTML Global arrays  Arguments not quoted  Use raw without assigning elements to local variables Note Appendix B, however Note some things in the form page (calc.php) JavaScript Arrays foreach() construct

13 Consider Some Enhancements Replace if() construct with switch() construct Check 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

14 Appendix

15 A PHP Application Note 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)monthly payment 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

16 Names to Use for Controls Use conventions from programming languages: Java, C++, Visual Basic Typically First 3 characters lowercase and type of control Uppercase only when words joined (intercap) Control TypePrefixExample TextboxtxttxtFirstName Text AreatxttxtFeedback CheckboxchkchkRetirement Option ButtonoptoptClass Dropdown ListlstlstWeekDay Submit ButtoncmdcmdCalculatePay

17 Review: Browser/Server Interaction


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

Similar presentations


Ads by Google