1 / 50

A pache M ySQL P hp

A pache M ySQL P hp. Robert Mudge. Reference: http://www.w3schools.com/php/. What is Apache? www.apache.org. Apache is the de-facto standard in web servers, it is FOSS Apache powers over 70% of all web sites Apache is secure, reliable and fast

moeshe
Download Presentation

A pache M ySQL P hp

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Apache MySQL Php Robert Mudge Reference: http://www.w3schools.com/php/

  2. What is Apache?www.apache.org • Apache is the de-facto standard in web servers, it is FOSS • Apache powers over 70% of all web sites • Apache is secure, reliable and fast • Apache is easy to install and configure • Apache will run on Windows, Linux and UNIX

  3. What is PHP?www.php.net • PHP stands for PHP: Hypertext Preprocessor • PHP is a server-side scripting language, like ASP • PHP scripts are executed on the server • PHP supports many databases (MySQL, Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.) • PHP is an open source software (OSS) • PHP is free to download and use

  4. What is MySQL?www.mysql.com • MySQL is a small database server • MySQL is ideal for small and medium applications • MySQL supports standard SQL • MySQL compiles on a number of platforms • MySQL is free to download and use

  5. PHP + MySQL + Apache • PHP combined with MySQL are cross-platform (means that you can develop in Windows and serve on a Unix platform)

  6. Learning Pyramid PHP SQL Program Design Cascading Style Sheets HTML/xHTML Scripting Object Oriented Design Programming C++/Java Internet / Web Server / Database Server

  7. System Configuration • Apache Server Installation • Apache/conf/httpd.conf • Add module php • MySQL Server Installation • my.ini • passwords • PHP Installation • php.ini • add module for MySQL

  8. Debugging in Php • Php.ini settings • Print statements • Debuggers • Dbg (http://dd.cron.ru/dbg/) • Gubed (http://sourceforge.net/projects/gubed/) • Summaryhttp://www-128.ibm.com/developerworks/library/os-debug/

  9. PHP Introduction • PHP File • HTML Header • PHP script delimiter • PHP Comments • PHP Variables • PHP Language • PHP Functions/Manual

  10. What is a PHP File? • PHP files may contain text, HTML tags and scripts • PHP files are returned to the browser as plain HTML  • PHP files have a file extension of ".php", ".php3", or ".phtml"

  11. HTML File Format <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> </head> <body> </body> </html>

  12. xHTML File Format Add Doc Type <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /><meta name="Keywords“ content="beginner, mysql, php, apache” /><meta name="Description" content="web building course" /><meta http-equiv="pragma" content="no-cache" /> <meta http-equiv="cache-control" content="no-cache" /> <link rel="stylesheet" type="text/css" href=“mystyle.css" /> <title>Page Title</title> </head> <br /><body></body> </html> Well FormedAll Tags open and close <tag></tag> or <tag />

  13. PHP Script Delimiters <html> <body> <?php echo "Hello World"; ?> </body> </html>

  14. PHP Comments <html> <body><?php //This is a comment /* This is a comment block */ ?></body> </html>

  15. PHP Variables • Variable Naming Rules • A variable name must start with a letter or an underscore "_" • A variable name can only contain alpha-numeric characters and • underscores (a-Z, 0-9, and _ ) • A variable name should not contain spaces. If a variable name • should be more than one word, it should be separated with • underscore ($my_string), or with capitalization ($myString)

  16. PHP Variables + Concatenation <html> <body> <?php $txt1="Hello World"; $txt2="1234"; echo $txt1 . " " . $txt2 ; ?> </body> </html>

  17. Arithmetic Operators

  18. Assignment & Comparison

  19. Logical Operators

  20. If – elseif - else

  21. switch-case-default

  22. PHP Arrays • When working with PHP, sooner or later, you might want to create many similar variables. Instead of having many similar variables, you can store the data as elements in an array. • Each element in the array has its own ID so that it can be easily accessed. • There are three different kind of arrays: • Numeric array - An array with a numeric ID key • Associative array - An array where each ID key is associated with a value • Multidimensional array - An array containing one or more arrays

  23. Numeric Arrays • A numeric array stores each element with a numeric ID key. • There are different ways to create a numeric array.

  24. Numeric Array - Examples Output: Quagmire and Joe are Peter's neighbors

  25. Associative Arrays • An associative array, each ID key is associated with a value. • When storing data about specific named values, a numerical array is not always the best way to do it. • With associative arrays we can use the values as keys and assign values to them.

  26. Associative Array - Example • Example 1 In this example we use an array to assign ages to the different persons:

  27. Associative Array - Examples Output: Peter is 32 years old.

  28. Multi-dimensional Arrays • In a multidimensional array, each element in the main array can also be an array. • Each element in the sub-array can be an array, and so on.

  29. Multi-dim Array Example

  30. Repetition and Looping • Very often when you write code, you want the same block of code to run a number of times. You can use looping statements in your code to perform this. • In PHP we have the following looping statements: • while - loops through a block of code if and as long as a specified condition is true • do...while - loops through a block of code once, and then repeats the loop as long as a special condition is true • for - loops through a block of code a specified number of times • foreach - loops through a block of code for each element in an array

  31. while loop Zero to n loops

  32. do – while Loop At least once + n loops

  33. for loop - repetition • The for statement is used when you know how many times you want to execute a statement or a list of statements. • Note: The for statement has three parameters. The first parameter initializes variables, the second parameter holds the condition, and the third parameter contains the increments required to implement the loop. If more than one variable is included in the initialization or the increment parameter, they should be separated by commas. The condition must evaluate to true or false.

  34. for loop - example

  35. foreach loop • The foreach statement is used to loop through arrays. • For every loop, the value of the current array element is assigned to $value (and the array pointer is moved by one) - so on the next loop, you'll be looking at the next element.

  36. foreach - Example

  37. Php Functions • A function is a block of code that can be executed whenever we need it. • Creating PHP functions: • All functions start with the word "function()" • Name the function - It should be possible to understand what the function does by its name. The name can start with a letter or underscore (not a number) • Add a "{"  - The function code starts after the opening curly brace • Insert the function code • Add a "}"  - The function is finished by a closing curly brace

  38. Function Example <html> <body> <?php function writeMyName() { echo “John Smith"; } writeMyName(); ?> </body> </html>

  39. Function Parameters <html> <body> <?php function writeName($first, $second) { echo $first . “ $second” . ‘<br>’; } writeName(‘John’, ‘Smith’); ?> </body> </html>

  40. Function Returns <html> <body> <?php function getName($first, $second) { $name = $first . “ $second” . ‘<br>’; return $name; } getName(‘John’, ‘Smith’); ?> </body> </html>

  41. Forms and User Input • The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. • The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts. • print_r($_POST); • echo $_SERVER['PHP_SELF'];

  42. Forms Example input.php welcome.php

  43. Form Validation • User input should be validated on the browser whenever possible (by client scripts (JavaScript)). Browser validation is faster and you reduce the server load. • You should consider using server validation if the user input will be inserted into a database. • A good way to validate a form on the server is to post the form to itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This makes it easier to discover the error.

  44. Php $_GET • The $_GET variable is used to collect values from a form with method="get". • The $_GET variable is an array of variable names and values sent by the HTTP GET method. • The $_GET variable is used to collect values from a form with method="get". Information sent from a form with the GET method is visible to everyone (it will be displayed in the browser's address bar) and it has limits on the amount of information to send (max. 100 characters).

  45. Php $_GET Example input.php welcome.php http://localhost/welcome.php?name=Peter&age=37

  46. Php $_GET Considerations • When using the $_GET variable all variable names and values are displayed in the URL. • This method should not be used when sending passwords or other sensitive information. • The variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases. • The HTTP GET method is not suitable on large variable values; the value cannot exceed 100 characters.

  47. Php $_REQUEST • The PHP $_REQUEST variable contains the contents of both $_GET, $_POST, and $_COOKIE. • The PHP $_REQUEST variable can be used to get the result from form data sent with both the GET and POST methods.

  48. Php $_POST • $_POST variable is used to collect values from a form with method="post". • The $_POST variable is an array of variable names and values sent by the HTTP POST method. • The $_POST variable is used to collect values from a form with method="post". Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.

  49. Php $_POST Example input.php welcome.php

  50. Homework #2 • Create a Login Web Page • User enters “username” and “password” • Upon successful input and comparison to a hard coded password, present a welcome page showing the username and password • Turn in your source code and screen captures from the operation through a web server.

More Related