Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Intro to Web Development with PHP - Lesson 1

Intro to Web Development with PHP - Lesson 1

Presented by Michael Cheng
at SPH Digital

Sample Code: https://github.com/sgphpug/intro-web-dev-php

Michael Cheng

August 25, 2018
Tweet

More Decks by Michael Cheng

Other Decks in Programming

Transcript

  1. What is PHP? • Computer programming software that is mostly

    used for building websites. • Developed by Rasmus Lerdorf in 1994. • Collection of small computer programs / scripts that he used to build websites. • PHP/FI - Personal Home Page / Forms Interpreter
  2. What is PHP? • 1997 - Andi Gutmans & Zeev

    Suraski helped to turn it into a real programming language (PHP 3.0) • PHP: Hypertext Preprocessor • PHP 3 Released in June 1998 • One of the most commonly used programming language used for building dynamic websites.
  3. How do I use PHP? • Most commonly used in

    a web server. • Web server is a software connected to a computer network (Internet or LAN), that is meant to share hypertext documents (HTML). • Nowadays u can get all sorts of multimedia files from a web server.
  4. Anatomy of a HTML document • Everything is a tag

    • Head • Body • Headers • Paragraph • Anchor • Lists
  5. Why PHP? • HTML documents (web pages) were all hand

    coded. • Updating the documents soon became very tedious. • Eg. Current date, Good morning. • Want to be able to collect info on the web page as well. • ie. web pages needed to be dynamic & interactive.
  6. Why PHP? • There has to be a easier /

    faster way of updating web pages. • Let’s make the web servers smarter & more dynamic. • Let’s do things with a database.
  7. Let's setup a web server! • Setting up WAMP /

    MAMP • http://wampserver.com • http://mamp.info • Windows Apache MySQL PHP • Mac Apache MySQL PHP
  8. PHP is an interpreted language • Special markups (PHP tag)

    let the web server know that certain portions of a web page are PHP & needs to be treated by the PHP interpreter • Opposite of interpreted language is a compiled language (Java, C, C++) • Must end each line with a semi-colon.
  9. PHP is an interpreted language • PHP Tags <?php ?>

    Normal PHP Tag <? ?> Short Tag • Commenting: Adding comments in the code that does not get printed out or interpreted by PHP. // Some Comment # Other comments /* More Comments */
  10. Let's write some PHP! • Download & install Visual Studio

    Code • https://code.visualstudio.com/Download • Hello world with date/time (introduce PHP build-in function) • Hello world with user input (URL parameter) • Hello world with form GET • Hello world with form POST • Upload file with a form • Show uploaded image
  11. What are data types? • How do u present them?

    • Simple data types (non-composite, scalar): • Strings, Integers, Boolean • Complex, multi-dimensional, composite: • Array, Object • Resource (file, DB connection)
  12. How do I store these data & pass them around?

    • Within the same PHP file. • Variable - container of information, info can be of any type & can be changed anytime • Constants - Another kind of container where once the info is set, you cannot change it.
  13. How do I store these data & pass them around?

    • Between different PHP files. • URL parameters
 (eg. http://localhost/hello.php?name=Michael) • HTML Form (POST/GET) • Cookie - Pieces of info related to a website visitor stored in the web browser • Session Variables - Information related to a website visitor stored in the web server
  14. When to use which method? • Is it changeable? •

    How big is the data? • How sensitive is the data? • Passed within the same file? • Passed between between pages in the same site? • Passed between different web sites (domain name)