Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the...
-
Upload
julie-brown -
Category
Documents
-
view
223 -
download
0
Transcript of Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the...
![Page 1: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/1.jpg)
Introduction to PHP and Server Side
Technology
![Page 2: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/2.jpg)
Slide 2
PHP History Created in 1995 PHP 5.0 is the current version
It’s been around since 2004
![Page 3: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/3.jpg)
Slide 3
General PHP Characteristics (1) PHP is made up of a PHP scripting block
PHP scripting blocks can appear anywhere in a Web page
In addition to PHP scripting blocks, PHP documents typically contain HTML
A page having embedded PHP script must have a file suffix of .php
![Page 4: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/4.jpg)
Slide 4
General PHP Characteristics (2) Like ASP.NET PHP is server-side
technology It runs on nearly all Web servers There is an IIS version
It’s open source It talks to databases
MySQL and others Facebook is a PHP application
![Page 5: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/5.jpg)
Slide 5
General PHP Characteristics (2) PHP works with XML PHP supports AJAX PHP supports cookies
![Page 6: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/6.jpg)
Slide 6
The Basics of PHP Syntax PHP scripts always appears between <?php and ?> PHP statements always end in a semi-
colon Comments have the same format as
JavaScript PHP KEYWORDS ARE NOT CASE
SENSITIVE BUT VARIABLE NAMES ARE
![Page 7: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/7.jpg)
Slide 7
A First PHP Program As in <html> <body><?phpecho "Hello";?> </body></html>
![Page 8: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/8.jpg)
Slide 8
PHP Variables Like JavaScript, variables are ‘loosely
typed’ Variables can be declared anywhere in a
PHP script Variable names
Must begin with a letter or underscore ‘_’ character
The remaining characters can be letters, numbers or the underscore
Variables cannot contain spaces
![Page 9: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/9.jpg)
Slide 9
PHP Variables (Declaring) Variable declarations begin with the
dollar sign ‘$’, followed by the variable name
An equals sign and value follow the declaration
Examples:$userName = “joe”;
$pi = 3.14;
![Page 10: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/10.jpg)
Slide 10
PHP Variables (Scope) Global variables are declared outside of a
function Use the global keyword to access variables
from a function
Local variables are declared within a function
Works the same way as JavaScript
![Page 11: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/11.jpg)
Slide 11
Using Numeric Variables (1) Arithmetic operations work similarly in PHP
and JavaScript Use print or echo to write output
print returns 1 while echo returns nothing Use the $ to reference all variable names
$x = 10;
$y = 100;
print $x + $y; /* 110 */
![Page 12: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/12.jpg)
Slide 12
Using Numeric Variables (2) The following prints 10 + 100 because
the value is quoted
$x = 10;
$y = 100;
print "$x + $y";
![Page 13: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/13.jpg)
Slide 13
PHP Strings (Introduction) Strings work in PHP the same way they
work in other languages There are several string functions:
http://w3schools.com/php/php_ref_string.asp
The dot (.) is the concatenation operator
![Page 14: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/14.jpg)
Slide 14
PHP Data Types Similar to JavaScript
![Page 15: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/15.jpg)
Slide 15
A First Server Round Trip Using Forms (1) Remember form widgets from
JavaScript <input type=“text”> and so on Remember widgets are contained in a
form Widgets are visible from PHP script so
we can process their contents on the server
![Page 16: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/16.jpg)
Slide 16
A First Server Round Trip Using Forms (2) The following form posts to the page
named Welcome.php (action attribute)
<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
![Page 17: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/17.jpg)
Slide 17
A First Server Round Trip Using Forms (3) Welcome.php contains the script to
process the posted data<html>
<body>
Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.
</body>
</html>
![Page 18: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/18.jpg)
Slide 18
A First Server Round Trip Using Forms (4)
![Page 19: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/19.jpg)
Slide 19
GET and POST (Introduction) There are two basic ways to send data
back to a Web server We call these HTTP verbs
In all there are about 30 verbs http://annevankesteren.nl/2007/10/http-me
thods Both GET and POST send data to Web
servers
![Page 20: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/20.jpg)
Slide 20
HTTP GET GET sends is data through the URL itself
as a query string The URL looks something like this
http://localhost/PhpProjectDemo1/welcome.php?fname=zaphod&age=42
<input> values appear after the ? Data appears as key=value pairs A & separates each key=value pair You don’t write the URL – HTTP does!
![Page 21: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/21.jpg)
Slide 21
HTTP POST The request data does not appear inside
the query string Data is sent in the HTTP header itself
It’s possible to pull this data out of the header
![Page 22: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/22.jpg)
Slide 22
HTTP GET and POST (Comparison) GET
Query strings are small (100 characters) Posted data is visible It’s possible to bookmark the page
PUT Large data blocks can be posted Posted data is hidden Page cannot be bookmarked
![Page 23: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/23.jpg)
Slide 23
Reading Posted Data $_GET and $_POST retrieve data send to
the server via a GET or POST, respectively
They are built-in functions Pass the ID of the input control as an
argument
![Page 24: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/24.jpg)
Slide 24
Example
<html>
<body>
Welcome <?php echo $_GET["fname"]; ?>!<br />
You are <?php echo $_GET["age"]; ?> years old.
</body>
</html>
![Page 25: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/25.jpg)
Slide 25
PHP Functions (Introduction) PHP has built-in functions just like any
language In all, there are about 700 so we will not
get to all of them Refer to
http://w3schools.com/php/default.asp for a categorized list
![Page 26: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/26.jpg)
Slide 26
PHP Functions (Syntax) It all looks just about like JavaScript
(except the $ notation for variables) Functions and accept 0, 1 or many
arguments Functions and return a value
Again, the arguments are loosely typed
![Page 27: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/27.jpg)
Slide 27
Declaring a PHP Function (Example) Declare a function named ShowFooter<?php
function ShowFooter()
{
print("<br />");
print(“Rendered " . date("y-m-d"));
print("<br />");
}
?>
![Page 28: Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.](https://reader035.fdocuments.net/reader035/viewer/2022062516/56649e155503460f94afeffa/html5/thumbnails/28.jpg)
Slide 28
Calling a Function (Example) Call the ShowFooter function shown
previously
<?php ShowFooter(); ?>