+ All Categories
Home > Documents > הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by...

הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by...

Date post: 17-Jan-2016
Category:
Upload: sharon-harrison
View: 249 times
Download: 0 times
Share this document with a friend
15
ההההה4
Transcript
Page 1: הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris. דף אינטרנט דינמי משתנה עפ " י הרצת

4הרצאה

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

אינטרנט דף של דינמיעיבוד

.Murach’s PHP and MySQL by Joel Murach and Ray Harrisמתוך

Web Server

PHPScript

Database Server

HTTP request

HTTP response`

Web Browser

" על קוד הרצת י עפ משתנה דינמי אינטרנט דףעדכון, בכל להשתנות יכול השרת

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

דינמי אינטרנט דף של העיבוד תהליך

• 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.

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

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:<?phpecho "My first PHP script!";?>

Installed as part of WAMP

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

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

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

PHP Syntax

A PHP script can be placed anywhere in the document. A PHP script starts with <?php and ends 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

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

Output to HTML: Echo / print

Echos what is in ” ” to the html. Any html can be input…

Examples echo ”hi”; echo ”<br>”; echo”<h1>blabla</h1>”; echo “<script>alert(‘careful’)</script>;

There is also a print function: print "Hello world!<br>";

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

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

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

Functions

Aside from built in functions, we can write our own:

<?phpfunction sum($x, $y) {    $z = $x + $y;    return $z;}

echo "5 + 10 = " . sum(5, 10) . "<br>";echo "7 + 13 = " . sum(7, 13) . "<br>";echo "2 + 4 = " . sum(2, 4);?>

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

Arrays

Indexed array:<?php$cars = array("Volvo", "BMW", "Toyota");$arrlength = count($cars);for($x = 0; $x < $arrlength; $x++) {    echo $cars[$x];    echo "<br>";}?>

Associative array (use named keys that you assign to them):

<?php$age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");echo "Peter is " . $age['Peter'] . " years old.";?>

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

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

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

$_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:

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

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

And other places…


Recommended