ISTE - 240 Week 8
Intro to PHP
HTML Document Request Workflow
Firsts here is a reminder of how we have been doing things (web and mobile 1, and up to now in web and mobile 2)
PHP Document Request Workflow
Firsts here is a reminder of how we have been doing things (web and mobile 1, and up to now in web and mobile 2)
Hello World PHP Script
Question: What is the problem here?
Hello World PHP Script
Answer: It wasn’t uploaded to a server!
Hello World PHP Script
Now that we moved it to a server that supports PHP it should work
Hello World PHP Script
��
Hello World PHP Script
PHP Parsing and Variables
Predefined ‘environmental’ Variables
Predefined ‘environmental’ Variables
Notice the use of var_dump? This can often times be used for debugging to print out the structure of an array or object.
Predefined ‘environmental’ Variables
Line 14 – there is an echo of a hr tag
Line 15 – there is an echo of the $_SERVER variable
Line 16, I ended the PHP directive (started on line 12)
Line 17 – a simple <hr/> tag
Line 18 – restarted a new PHP directive
Line 19 – echo out the variable dump of $_SERVER
Predefined ‘environmental’ Variables
Line 19 – echo out the variable dump of $_SERVER
echo “My port is: “ . $_SERVER[“SERVER_PORT”];
Make sense? I can access any of the 79 by its name. This approach for accessing information from an associative array will also be how we get data from databases – so it is good to start seeing it now!
GET & POST Environmental Variables
Line 22 to 26 is a simple if statement – but 22 is looking for something specific. It is looking to the URL to see if there is a GET with the name of ‘test’ that was included. The isset() method is a predefined PHP method (color coding is your friend) that checks if it is there at all.
GET & POST Environmental Variables
VERSUS
COMPARE:
1
2
Notice the URL argument we have here? We will go over this in more depth in later weeks.
Other PHP examples
Some Handy Built in PHP functions: phpinfo()
<!DOCTYPE html>�<html>�<body>��<?php�$t = date("H");��if ($t < "20") {� echo "Have a good day!";�} else {� echo "Have a good night!";�}�?>� �</body>�</html>
Other PHP examples
Some Handy Built in PHP functions: Date()
Other PHP examples
Some Handy Built in PHP functions: Arrays and explode / implode
Other PHP examples
Some Handy Built in PHP functions: Arrays and explode / implode
Source: https://www.c-sharpcorner.com/UploadFile/051e29/implode-and-explode-function-in-php/
Other PHP examples
Some Handy Built in PHP functions: Arrays and explode / implode
Source: https://www.c-sharpcorner.com/UploadFile/051e29/implode-and-explode-function-in-php/
Additional Time Left Over?
Time for Questions and More Demos