PHP for Server Side Preprocessing Chapter 08: Overview and Objectives

PHP for Server Side Preprocessing Chapter 08: Overview and Objectives
paly

This chapter provides a brief history of PHP and discusses its role in the overall web development process. It also covers various PHP script development techniques and includes practical examples such as generating welcome messages, implementing server-side functionality and email communication, and using the POST method to submit form data. Other topics covered include Comments, variables, data types, expressions and operators, arrays, functions, file output, and server-side file inclusion.

  • Uploaded on | 4 Views
  • sunniva sunniva

About PHP for Server Side Preprocessing Chapter 08: Overview and Objectives

PowerPoint presentation about 'PHP for Server Side Preprocessing Chapter 08: Overview and Objectives'. This presentation describes the topic on This chapter provides a brief history of PHP and discusses its role in the overall web development process. It also covers various PHP script development techniques and includes practical examples such as generating welcome messages, implementing server-side functionality and email communication, and using the POST method to submit form data. Other topics covered include Comments, variables, data types, expressions and operators, arrays, functions, file output, and server-side file inclusion.. The key topics included in this slideshow are PHP, server-side preprocessing, web development, script development, practical examples, feedback form, email communication, POST method, comments, variables, data types, expressions, operators, arrays, functions, file output, file inclusion,. Download this presentation absolutely free.

Presentation Transcript


1. PHP for Server-Side Preprocessing Chapter 08

2. Overview and Objectives Overview and Objectives Present a brief history of the PHP language Discuss how PHP fits into the overall web picture Discuss PHP script development and testing Incorporate into our home page a PHP-generated welcome message Show how to cause our home page to be refreshed (reloaded) every so often Implement the server-side functionality of our feedback form: sending the users feedback to the business via email, sending a copy of the e-mail to the client, storing a copy of the feedback on the server Implement an alternate version of our BMI calculator Show how to send HTML-encoded e-mail Use the POST value of the method attribute of the form element to submit form data Discuss several features of the PHP language, as required for our purposes: Comments variables (including superglobals ) , numerical and string data types, expressions and operators, arrays, built-in and programmer defined functions, file output, server-side inclusion of files Chapter 08: PHP for Server-Side Preprocessing

3. PHP History PHP History PHP stood for Personal Home Page , when originally implemented by Rasmus Lerdorf in 1995 for tracking accesses to his online resume. A revised version was called PHP/FI, where FI stood for Forms Interpreter. Now users prefer to use the recursive name PHP: Hypertext Preprocessor. Perl was the language of choice for server-side computing prior to PHP. Constructs of PHP: Origins in Perl and similar to JavaScript. Source code for PHP was made public and that led to a vibrant community of developers. Chapter 08: PHP for Server-Side Preprocessing

4. PHP as a Server-Side Scripting Language PHP as a Server-Side Scripting Language Most web servers support a PHP interpreter. May not automatically have access to PHP on a server provided by an ISP. PHP has to be activated and configured for use A web server may spawn a separate operating system process to handle PHP requests, or it may be built- into the server: This will be transparent to the user. PHP-related pages provided on the CD-ROM cannot be viewed directly from the CD-ROM. PHP-related pages will need to be uploaded to a PHP- enabled web server in order to function properly. Chapter 08: PHP for Server-Side Preprocessing

5. PHP: A Simple Example welcome.php PHP: A Simple Example welcome.php Welcome Message with Output from the PHP date() Function

Welcome!

It's ".date("l, F jS").".
"; echo "The time is ".date("g:ia")."."; ?> Chapter 08: PHP for Server-Side Preprocessing

6. Diving Right In: What do we see in welcome.php ? Diving Right In: What do we see in welcome.php ? A PHP script between the PHP delimiters: Two PHP echo statements that send strings containing markup to the web page (note that statements end with a semicolon). The use of the PHP built-in function date() to return a date value for inclusion in the web page. date("l, F jS") returns the current date as a string, with the day in long ( l ) form, the full ( F ) name of the month, the date of the month in the Julian calendar ( j ), with the appropriate suffix ( S ) appended (the comma and two spaces are just literal characters) date("g:ia") actually returns a time, rather than a date, again as a string, with g giving the hour in 12-hour format with no leading zeros, i giving the minutes with leading zeros, and a causing am or pm to be appended, as appropriate (the colon is a literal character) The (somewhat unorthodox) use of the period (.) as the string concatenation operator in PHP. Can you spot which periods are used like this, and which are just periods at the ends of sentences? Chapter 08: PHP for Server-Side Preprocessing

7. A Browser Display of welcome.php A Browser Display of welcome.php Chapter 08: PHP for Server-Side Preprocessing Courtesy of Natures Source

8. A Browser Display of index.php : Now Contains A Welcome Message, with Date and Time from the PHP Script Output A Browser Display of index.php : Now Contains A Welcome Message, with Date and Time from the PHP Script Output Chapter 08: PHP for Server-Side Preprocessing Courtesy of Natures Source, (inset) Photos.com

9. Our New Index File: index.php (1 of 2) Our New Index File: index.php (1 of 2) Nature's Source - Canada's largest specialty vitamin store

Chapter 08: PHP for Server-Side Preprocessing

10. Our new index file: index.php (2 of 2) Our new index file: index.php (2 of 2)

Welcome to Nature's Source: Protecting your health naturally!

Founded in 1998, Nature's Source was created to serve those who use alternative healing methods. Offering only the highest quality vitamins, minerals, supplements & herbal remedies, Nature's Source takes great pride in helping people live healthier, happier lives.

Many Companies that talk about Customer Service fail to deliver. Nature's Source exists to truly serve all the needs of their customers. Each location features dedicated on-site therapists along with knowledgeable staff who ensure that every customer receives the best quality information available. Continuing Education seminars are a regular event at Nature's Source.

Healthy Lifestyle
Chapter 08: PHP for Server-Side Preprocessing

11. Markup from Our New Banner File: Extends the previous logo.html Markup from Our New Banner File: Extends the previous logo.html

Welcome!

It's ".date("l, F jS").".
"; echo "Our time is ".date('g:ia')."."; ?>
Chapter 08: PHP for Server-Side Preprocessing

12. A Firefox browser display of feedback.php A Firefox browser display of feedback.php Chapter 08: PHP for Server-Side Preprocessing Courtesy of Natures Source

13. The Revised form Tag in feedback.html Invokes a Server-Side PHP Script for Processing When the Input Data is Valid The Revised form Tag in feedback.html Invokes a Server-Side PHP Script for Processing When the Input Data is Valid

Chapter 08: PHP for Server-Side Preprocessing

14. PHP Code to Process Feedback in processFeedback.php (1 of 2) PHP Code to Process Feedback in processFeedback.php (1 of 2)

15. PHP Code to Process Feedback in processFeedback.php (2 of 2) PHP Code to Process Feedback in processFeedback.php (2 of 2) //Send the confirmation message to the client $headerToClient = "From: webbook@cs.smu.ca\r\n"; mail($_POST['email'], "Re: ".$_POST['subject'], $messageToClient, $headerToClient); //Transform the confirmation message to the client into XHTML format and display it $display = str_replace("\r\n", "
\r\n", $messageToClient); $display = "Your Message". $display. ""; echo $display; //Log the message in a file called feedback.txt on the web server $fileVar = fopen("../data/feedback.txt", "a") or die("Error: Could not open the log file."); fwrite($fileVar, "\n-------------------------------------------------------\n") or die("Error: Could not write to the log file."); fwrite($fileVar, "Date received: ".date("jS \of F, Y \a\\t H:i:s\n")) or die("Error: Could not write to the log file."); fwrite($fileVar, $messageToBusiness) or die("Error: Could not write to the log file."); ?>

16. An e-mail Display Showing the e-mail Received by the Business as a Result of the Form Being Processed by processFeedback.php An e-mail Display Showing the e-mail Received by the Business as a Result of the Form Being Processed by processFeedback.php Chapter 08: PHP for Server-Side Preprocessing

17. An e-mail Display Showing the e-mail Received by the Client as a Result of the Form Being Processed by processFeedback.php An e-mail Display Showing the e-mail Received by the Client as a Result of the Form Being Processed by processFeedback.php Chapter 08: PHP for Server-Side Preprocessing

18. A Browser Display of Processing from processFeedback.php Showing Confirmation to the User That the Feedback Form Input Has in Fact Been Received A Browser Display of Processing from processFeedback.php Showing Confirmation to the User That the Feedback Form Input Has in Fact Been Received Chapter 08: PHP for Server-Side Preprocessing Courtesy of Natures Source

19. The Feedback Message, with Date of Submission, As It Is Stored on the Server in a Log File Called feedback.txt in the Subdirectory nature/data The Feedback Message, with Date of Submission, As It Is Stored on the Server in a Log File Called feedback.txt in the Subdirectory nature/data From: Mr. Pawan Lingras E-mail address: pawan@cs.smu.ca Phone number: 5798 Subject: Hello Thank you for providing me with an opportunity to look at various health alternatives. I was wondering if you had some products that will help me reduce my cholesterol. Thank you for the feedback and your patronage. -- Naturally Yours! team P.S. We will contact you shortly with more information. Chapter 08: PHP for Server-Side Preprocessing

20. Chapter 08: PHP for Server-Side Preprocessing

21. A browser display of bmi.php A browser display of bmi.php Chapter 08: PHP for Server-Side Preprocessing Courtesy of Natures Source

22. A browser Display of Processing from processBMI.php A browser Display of Processing from processBMI.php Chapter 08: PHP for Server-Side Preprocessing Courtesy of Natures Source

23. E-mail Received by the Client As a Result of Processing from processBMI.php E-mail Received by the Client As a Result of Processing from processBMI.php Chapter 08: PHP for Server-Side Preprocessing Courtesy of Natures Source

24. The Revised form Tag Which Invokesa PHP Script for Processing the Form Data from bmi.php The Revised form Tag Which Invokesa PHP Script for Processing the Form Data from bmi.php Chapter 08: PHP for Server-Side Preprocessing

25. PHP Code to Process BMI in processBMI.php PHP Code to Process BMI in processBMI.php Your BMI

The report has also been sent to you via e-mail."; } ?>

Chapter 08: PHP for Server-Side Preprocessing

26. PHP Programmer-defined Functions (1 of 4) PHP Programmer-defined Functions (1 of 4) BMI Report". "

Your BMI is ".$bmi.".

"; return $text; } Chapter 08: PHP for Server-Side Preprocessing

27. PHP Programmer-defined Functions (2 of 4) PHP Programmer-defined Functions (2 of 4) function detailedMessage($height, $heightUnit, $weight, $weightUnit) { $bmi = sprintf("%.2lf", calculateBMI($height, $heightUnit, $weight, $weightUnit)); $text = //"

"."Nature"."

". "

BMI Report

". "

Your height: ".$height." ".$heightUnit."
". "Your weight: ".$weight." ".$weightUnit."
". "Your BMI: ".$bmi."

"; if ($bmi < 18.5) $text .= "

Your BMI suggests that you are underweight.

"; else if ($bmi < 25) $text .= "

Your BMI suggests that you have a reasonable weight.

"; else if ($bmi < 29) $text .= "

Your BMI suggests that you are overweight.

"; else $text .= "

Your BMI suggests that you may be obese.

"; return $text; } Chapter 08: PHP for Server-Side Preprocessing

28. PHP Programmer-defined Functions (3 of 4) PHP Programmer-defined Functions (3 of 4) function inchesToCentimetres($height){return $height*2.54; } function poundsToKilograms($weight){return $weight/2.2; } function calculateBMI($height, $heightUnit, $weight, $weightUnit) { if ($heightUnit == "inches") $height = inchesToCentimetres($height); if ($weightUnit == "pounds") $weight = poundsToKilograms($weight); $height /= 100; //Convert height from centimeters to meters $bmi = $weight/($height*$height); return $bmi; } Chapter 08: PHP for Server-Side Preprocessing

29. PHP Programmer-defined Functions (4 of 4) PHP Programmer-defined Functions (4 of 4) function mailBMI($email, $message) { $header = 'MIME-Version: 1.0' . "\r\n"; $header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $header .= "From: webbook@cs.smu.ca\r\n"; mail($email, "BMI report from Nature's Source", $message, $header); } ?> Chapter 08: PHP for Server-Side Preprocessing