🎧 New: AI-Generated Podcasts Turn your study notes into engaging audio conversations. Learn more

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Document Details

ZippyPelican

Uploaded by ZippyPelican

Wilfrid Laurier University

Tags

internet computing web development php

Full Transcript

CP476 Internet Computing Week 1 – 1 Introduction Shaun Gao, Ph.D., P.Eng. Agenda Course introduction and notifications What is Internet computing? HTTP How web server works Web Server side languages Introduction to PHP PHP basics PHP Case Sensitivity Comments in PHP Some useful resources Summary CP4...

CP476 Internet Computing Week 1 – 1 Introduction Shaun Gao, Ph.D., P.Eng. Agenda Course introduction and notifications What is Internet computing? HTTP How web server works Web Server side languages Introduction to PHP PHP basics PHP Case Sensitivity Comments in PHP Some useful resources Summary CP476A Course information Instructor: Lunshan (Shaun) Gao, PhD, P.Eng. Email: [email protected] Reference textbooks PHP for the Web, 5th edition by Larry Ullman, Publisher Peachpit Press 2016 Learning PHP, MySQL & JavaScript: A Step-by-Step Guide to Creating Dynamic Websites by Robin Nixon, Publisher O'Reilly 2021 Course format: Lectures: Mondays and Wednesdays Practices & Tutorials: Fridays (bring your own PC in classroom) Evaluation scheme Group project presentation Group project report Test 2x15% Final 15% 15% 30% 40% Course information – cont. Week1 – introduction Week2,3,4 – PHP and Apache Week5 –-PHP OOP-- (test 1) Week6 – PHP data object Week7,8 – JavaScript Week9 –-JavaScript event process-- (test 2) Week10 – Node.js introduction Week11 – group project presentation Week12 – group project presentation, project report due Prerequisite knowledge: HTML, HTTP protocol, C Database (MySQL) Academic Integrity Anything you submit for credit is expected to be your own work Course information – cont. Group project 3-4 students become a team for the project (1).Front end, (2).web server, (3). back end, (4).DB Send me an email to tell me your team members by the end of January. The project requirements in myls How your project will be evaluated 6 minute presentation (3 minutes theory, 3 minutes demo) Presentation evaluation rubrics, please refer to the rubrics in MyLS Project report – Software system design documentation or technical report Internet Computing What is computing? Use of a computer to process data or perform calculations Definition: Internet computing is an architecture that supports all information flows and processes over the Internet, it provides access to all applications. With Internet computing, all a user needs is a standard Web browser and security clearance. Examples of Internet computing https://onecompiler.com/php/3xq663r2h https://www.online-python.com/ https://onecompiler.com/javascript HTTP protocol HTTP (Hypertext Transfer Protocol) to communicate between web client and web server. HTTP is an application-layer protocol Request / Response Cycle You enter http://server.com into your browser’s address bar. Your browser looks up the IP address for server.com – DNS. Your browser issues a request to server.com using the IP address. The request crosses the Internet and arrives at the server.com web server. The web server, having received the request and analyze it. The web page is retrieved by the server and returned to the browser. Your browser displays the web page. HTTP request/response – without DB Request Response HTTP request/response – with DB. Request Response Apache web server Apache http server project http://httpd.apache.org Apache foundation started to support the web server project, but now extends to a multitude of other projects. Apache: the second place from market share perspective. Start Apache From the opened DOS command window, type the following from “{Your directory path}/Apache24/bin”. > httpd -k install Check that you can access http://localhost in your browser Configuration folder and file names conf: configuration files, httpd.conf htdocs: contains web pages  you can change it in configuration file Web Server side languages PHP is not the only language for server side programming. JavaScript (Node.js), Python, Java etc. PHP is the most used one based on https://w3techs.com/ Introduction to PHP Before you continue, you should have a basic understanding of the following: HTML CSS - optional JavaScript – we will learn it from week 7 If you want to study these subjects first, find the tutorials on https://www.w3schools.com/default.asp Introduction to PHP – cont. What is PHP? PHP is an acronym for "PHP: Hypertext Preprocessor" PHP is a widely-used, open-source scripting language PHP scripts are executed on the server PHP is free to download and use PHP is an amazing and popular language! PHP is a scrip language, and it can be run without compiling Introduction to PHP – cont. What is a PHP File? PHP files can contain text, HTML, CSS, JavaScript, and PHP code PHP code is executed on the server, and the result is returned to the browser as plain HTML PHP files have extension ".php" Example: Introduction to PHP – cont. What Can PHP Do? PHP can generate dynamic page content PHP can create, open, read, write, delete, and close files on the server PHP can collect data from Database (SQL, noSQL statements) PHP can send and receive cookies PHP can add, delete, modify data in database PHP can be used to control user-access PHP can encrypt data With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML. Introduction to PHP – cont. Why PHP? PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) PHP is compatible with almost all servers used today (Apache, IIS, etc.) PHP supports a wide range of databases PHP is free. Download it from the official PHP resource: www.php.net PHP is easy to learn and runs efficiently on the server side PHP basics PHP code is enclosed between Syntax: File name must have the extension.php, e.g. hello_world.php A PHP script consists of one or more statements and comments, there is no need for a main function (or classes) PHP basics –cont. PHP Case Sensitivity keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are not case-sensitive. For example - demo However, all variable names are case-sensitive! (PHP variable starts with $) $COLOR differs from $coLOR PHP basics –cont. Comments in PHP A comment in PHP code is a line that is not executed as a part of the program. Its only purpose is to help readers to understand the code. Syntax for single-line comments: Syntax for multiple-line comments: Summary HTTP How web server works Web Server side languages Introduction to PHP PHP basics PHP Case Sensitivity Comments in PHP Useful resources https://www.w3schools.com/php/default.asp https://sandbox.onlinephpfunctions.com/ Announcement Project is a group work. Three or Four of you become a group. Please send me an email by the end of January 2024. CP476 Internet Computing Week 1 – 2 PHP - Data types and Variables Shaun Gao, Ph.D., P.Eng. Agenda PHP processing Output methods Data types Integers and Floating-point numbers Booleans Strings Array, object Resource, NULL Data type conversion Variables https://www.w3schools.com/php/default.asp PHP processing PHP code is embedded into HTML pages using tags () Processing proceeds as follows: The web server receives a client request The web server recognizes that the client request is for a HTML document containing PHP code The server executes the PHP code, substitutes output into the HTML document, the resulting page is then send to the client The client never sees the PHP code, only the HTML document that is produced PHP output methods: echo and print With PHP, there are two basic ways to get output: echo and print Echo: The echo statement can be used with or without parentheses: echo or echo() such that, echo $var1; or echo($var1); Print: The print statement can be used with or without parentheses: print or print() such that, print $var1; or print($var1); Example: echo "I'm about to learn PHP! \n"; Print "I'm about to learn PHP too! \n"; echo ("I'm about to learn PHP! \n"); https://onlinephp.io/ PHP basics – data types PHP has eight datatypes before version 8 Four primitive types: bool - Booleans int - integers float - floating-point numbers string - strings Two compound types: array - arrays object - objects Two special types: resource NULL mixed is a pseudo type added in PHP 8 PHP basics– strings PHP distinguishes between single-quoted strings and double-quoted strings. PHP basics - array What is an array? Array is a data type that can hold more than one value at a time. How to create an array? array() function In PHP, there are three types of arrays: Indexed arrays - Arrays with a numeric index $cars = array("Volvo", "BMW", "Toyota"); $cars Associative arrays - Arrays with named keys $age = array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43"); Multidimensional arrays - Arrays containing one or more arrays PHP basics – array – examples. Example 1: Example 2: https://sandbox.onlinephpfunctions.com/ PHP basics – array – examples. Example 3: 2 dimensional array https://onlinephp.io/ PHP basics – objects. object – An object is a data type which stores not only data but also information on how to process that data. Unlike the other data types in PHP, an object type must be explicitly declared. A class is a template for objects, and an object is an instance of a class. Converting to object If an object is converted to another object, it is not modified. If arrays are converted to an object with properties named by keys, and corresponding values. For any other value, a member variable named scalar will contain the value. Example: $object = (object) $array; PHP basics – resource Resource A resource is a special data type that refers to an external resource. Resources are created and used by special functions. Examples of Resource Types PHP basics – NULL NULL The special null value represents a variable with no value. null is the only possible value of type null. A variable is considered to be null if: it has been assigned to null. it has not been set to any value yet (empty). it has been unset(). Example: $a = array(); echo $a == null; Question? (PHP NULL differs from NULL in C/C++) PHP predefined math functions PHP supports a wide range of pre-defined mathematical functions abs(number) ceil(number) floor(number) round(number [,prec,mode]) log(number [,base]) rand(min,max) sqrt(number) absolute value round fractions up round fractions down round fractions logarithm generate an integer random number square root PHP provides pre-defined number constants including M_PI NAN INF 3.14159265358979323846 `not a number' `infinity' PHP – NAN, INF, Booleans The constants NAN and INF are used as return values for some applications of mathematical functions that do not return a number log(0) returns -INF (negative `infinity') sqrt(-1) returns NAN (`not a number’) PHP has a Boolean datatype with constants TRUE and FALSE (case insensitive) PHP offers the same Boolean operators as C++, JavaScript && (conjunction) || (disjunction) Online demos PHP – type conversion to Boolean When converting to Boolean, the following values are considered FALSE: the Boolean the integer the float the string the empty string FALSE 0 (zero) 0.0 (zero) '0' (but not 0.0 nor '00') ‘’” Every other value is considered TRUE (including any resource) When converting a Boolean to a string, TRUE becomes "1" FALSE becomes "" PHP – type conversion in general Type casting is to utilize one data type variable into the different data type. Type casting is the explicit conversion of data type. Example: $string_var = "string value for php type"; $int_var = (array)$string_var; var_dump($int_var); PHP – variables All PHP variable names start with $ followed by a PHP identifier A PHP identifier consists of letters, digits, and underscores, but cannot start with a digit. PHP identifiers (variables) are case sensitive In PHP, a variable does not have to be declared before it can be used A variable also does not have to be initialised before it can be used, although initialisation is a good idea Uninitialized variables have a default value: PHP - variable Assignments PHP uses the equality sign = for assignments. Example: $b = ($a = 0) + 1; PHP also supports the standard binary assignment operators: PHP - constants Use the keyword “define” to define a constant or an array of constants. define(string, expr [, case_insensitive]) define ("PI" ,3.14159); define (" ANIMALS " ,[" bird "," cat"," dog" ]); The constant is globally accessible within a script Online demo: define ("PI" ,3.14159); Echo PI; Summary PHP processing Output methods Data types Integers and Floating-point numbers Booleans Strings Array, object Resource, NULL Data type conversion – not recommended Variables Announcement How about environment setup? Visual Studio Code as an IDE from week 2-3 Please send me an email with your group members’ full names by the end of January 2024. https://www.w3schools.com/php/default.asp CP476 Internet Computing Week 1 – 3 - Tutorial Shaun Gao, Ph.D., P.Eng. Agenda Review week 1 Left over demos Course evaluation rubrics Installation Apache, MySQL, and PHP Installation of VS Code Before VS Code is ready, you can use online interpreter https://onecompiler.com/php/3xq663r2h https://onlinephp.io/ PHP demos Review PHP processing Output methods Data types Integers and Floating-point numbers Booleans Strings Array, object Resource, NULL Data type conversion Variables PHP demos Build in math functions ceil(7.3) ceil(7.7) floor(7.2) floor(7.8) && and || operations Concatenation operator. Course evaluation review Project requirements Project evaluation rubrics Presentation Theory Demonstration Report (Software Design Doc or Technical report) The difference Installation Apache, MySQL, and PHP Myls document Installation of VS Code Myls document Q and A Installation Apache, MySQL, and PHP Installation of VS Code Before VS Code is ready, you can use online interpreter https://onecompiler.com/php/3xq663r2h https://onlinephp.io/ PHP practice Announcement Finding a group for the group project Please let me know if you need help Please send me an email with your group members’ full names by the end of January 2024. https://www.w3schools.com/php/default.asp

Use Quizgecko on...
Browser
Browser