Presentation is loading. Please wait.

Presentation is loading. Please wait.

הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.

Similar presentations


Presentation on theme: "הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות."— Presentation transcript:

1 הרצאה 4

2 עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות בכל עדכון

3 תהליך העיבוד של דף אינטרנט דינמי The web browser builds an HTTP request, and sends it to the relevant web server. If the user submitted data, it will be included in the request. The web server checks the file extension of the requested page. If it is PHP it invokes the PHP interpreter which is running on the web server. The PHP interpreter finds the relevant PHP script from the hard drive, along with any data it needs, and executes the script (it may request data from the database). The script generates an HTML page as output, and sends it to the client as an HTTP response. The response includes the HTML formatting for the page. The web browser (client) receives the HTTP response, and uses the HTML to format and display the page in the web browser. The browser does not know if the page was obtained from a static HTML page or generated using PHP.

4 PHP  PHP: Hypertext Preprocessor  What is a PHP File?  PHP files can contain text, HTML, CSS, JavaScript, and PHP code  PHP code are executed on the server, and the result is returned to the browser as plain HTML  PHP files have extension ".php"  Example:  Installed as part of WAMP

5 What Can PHP Do?  Generate dynamic page content  Create, open, read, write, delete, and close files on the server  Collect form data  Add, delete, modify data in your database  Can be used to control user-access  PHP can encrypt data  Send and receive cookies

6 PHP Syntax  A PHP script can be placed anywhere in the document.  A PHP script starts with :  The default file extension for PHP files is ".php".  A PHP file normally contains HTML tags, and some PHP scripting code.  In PHP, all keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are NOT case-sensitive.  However; all variable names are case-sensitive.  In PHP, a variable starts with the $ sign, followed by the name of the variable.  http://www.w3schools.com/php/default.asp http://www.w3schools.com/php/default.asp

7 Output to HTML: Echo / print  Echos what is in ” ” to the html.  Any html can be input…  Examples  echo ”hi”;  echo ” ”;  echo” blabla ”;  echo “ alert(‘careful’) ;  There is also a print function:  print "Hello world! ";

8 Data Types  Variables can store data of different types, they are not declared.  Strings (in single or double quotes) <?php $x = "Hello world!"; $y = 'Hello world!'; ?>  Integers $x = 5985;  For other types: http://www.w3schools.com/php/php_datatypes.asp http://www.w3schools.com/php/php_datatypes.asp

9 Conditional Statements  http://www.w3schools.com/php/php_if_else.asp http://www.w3schools.com/php/php_if_else.asp  http://www.w3schools.com/php/php_switch.asp http://www.w3schools.com/php/php_switch.asp  http://www.w3schools.com/php/php_looping.asp http://www.w3schools.com/php/php_looping.asp  http://www.w3schools.com/php/php_looping_for.a sp http://www.w3schools.com/php/php_looping_for.a sp

10 Functions  Aside from built in functions, we can write our own: "; echo "7 + 13 = ". sum(7, 13). " "; echo "2 + 4 = ". sum(2, 4); ?>

11 Arrays  Indexed array: "; } ?>  Associative array (use named keys that you assign to them): "35", "Ben"=>"37", "Joe"=>"43"); echo "Peter is ". $age['Peter']. " years old."; ?>

12 SuperGlobals  Several predefined variables in PHP are "superglobals“  They are always accessible, regardless of scope  You can access them from any function, class or file without having to do anything special.  The PHP superglobal variables are:  $GLOBALS  $_SERVER  $_REQUEST  $_POST  $_GET  $_FILES  $_ENV  $_COOKIE  $_SESSION

13 $_GET  PHP superglobal $_GET is used to collect form data.  $_POST is also a superglobal used to collect form data We will learn it later  The file welcome.php:

14 Form Validation  http://www.w3schools.com/php/php_form_validati on.asp http://www.w3schools.com/php/php_form_validati on.asp  Self reading…

15 Working With DB  With PHP, you can connect to and manipulate databases.  Some examples will be given in class document  Others can be found here  http://www.w3schools.com/php/php_mysql_intro.asp http://www.w3schools.com/php/php_mysql_intro.asp  And other places…


Download ppt "הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות."

Similar presentations


Ads by Google