Intro to Web Programming using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000.

Slides:



Advertisements
Similar presentations
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK) Lecture 3 PHP (2) : Functions, User Defined Functions & Environment Variables.
Advertisements

JavaScript and AJAX Jonathan Foss University of Warwick
PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.
PHP –Writing Reusable Code 10 March 2006 Adina Crainiceanu IT420: Database Management and Organization.
PHP Functions and Control Structures. 2 Defining Functions Functions are groups of statements that you can execute as a single unit Function definitions.
Server & Client  Client: Your computer  Server: Powerful & Expensive computer. Requires network access.
PHP (Hypertext Preprocessor) 1. PHP References From W3 Schools: PHP.
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
1 Introduction to PHP. 2 What is this “PHP” thing? Official description: “PHP, which stands for "PHP: Hypertext Preprocessor" is a widely-used Open Source.
Basic php. Php Official site: PhP manual: Useful package (Apache, MySql,PhP):
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.
INTERNET APPLICATION DEVELOPMENT For More visit:
PHP H ypertext P re-processor. Unit 6 - PHP - Hello World! - Data types - Control structures - Operators.
AIT 616 Fall 2002 PHP. AIT 616 Fall 2002 PHP  Special scripting language used to dynamically generate web documents  Open source – Free!!!  Performs.
1 HTML and CGI Scripting CSC8304 – Computing Environments for Bioinformatics - Lecture 10.
JavaScript JavaScript is a scripting language that is most commonly used to add client- side programming to a web page. Some of the things it is used for.
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
Lab 3: Language Structures User Interface Lab: GUI Lab Sep. 9 th, 2014.
Chap 3 – PHP Quick Start COMP RL Professor Mattos.
IST 210: PHP BASICS IST 210: Organization of Data IST210 1.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
SE-2840 Dr. Mark L. Hornick 1 Modifying webpage behavior using client-side scripting Javascript.
Server & Client  Client: Your computer  Server: Powerful & Expensive computer. Requires network access.
Tutorial 10 Programming with JavaScript
CS146 Database Systems &Team Projects Spring 2009.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
PHP Teresa Worner. What is it? PHP: Hypertext Preprocessor server-side scripting language open source cross-platform compatible with almost all servers.php.php3.phtml.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Intro to PHP IST2101. Review: HTML & Tags 2IST210.
PHP Open source language for server-side scripting Works well with many databases (e.g., MySQL) Files end in.php,.php3 or.phtml Runs on all major platforms.
XP Tutorial 10New Perspectives on HTML and XHTML, Comprehensive 1 Working with JavaScript Creating a Programmable Web Page for North Pole Novelties Tutorial.
JavaScript Syntax, how to use it in a HTML document
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
IS-907 Java EE World Wide Web - Overview. World Wide Web - History Tim Berners-Lee, CERN, 1990 Enable researchers to share information: Remote Access.
PHP A very brief introduction PHP1. PHP = PHP: Hypertext Processor A recursive acronym! PHP scripts are executed on the server side Executed by (a plugin.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP Basics.
Rich Internet Applications 2. Core JavaScript. The importance of JavaScript Many choices open to the developer for server-side Can choose server technology.
HTTP protocol Java Servlets. HTTP protocol Web system communicates with end-user via HTTP protocol HTTP protocol methods: GET, POST, HEAD, PUT, OPTIONS,
Intro to PHP More About PHP. So far we've covered... Web Servers & Protocols Presentation Layer (static pages) For the rest of the semester... Application.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
NMD202 Web Scripting Week2. Web site
PHP (cont.). 2 Functions Definition – function name(arguments){... } –syntax name as for a variable, but without $ arguments as for variables –to return.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
CGS 3066: Web Programming and Design Spring 2016 PHP.
IST 210: PHP Basics IST 210: Organization of Data IST2101.
PHP using MySQL Database for Web Development (part II)
PHP LANGUAGE MULTIPLE CHOICE QUESTION SET-5
CGS 3066: Web Programming and Design Spring 2017
>> Introduction to JavaScript
Introduction to Dynamic Web Programming
Tutorial 10 Programming with JavaScript
CS5220 Advanced Topics in Web Programming JavaScript and jQuery
PHP –MySQL Interview Question And Answer.
DBW - PHP DBW2017.
PHP Hypertext Preprocessor
PHP Introduction.
Web Systems Development (CSC-215)
Intro to PHP.
JavaScript CS 4640 Programming Languages for Web Applications
Tutorial 10: Programming with javascript
PHP an introduction.
PHP-II.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

Intro to Web Programming using PHP, HTTP, CSS, and Javascript Layton Smith CSE 4000

Intro Types in PHP Advanced String Manipulation The foreach construct $_REQUEST environmental variable Correction on extract and ereg Easier file access The session How to use include and require functions and scope HTTP, CSS, Javascript What does it all mean??? Debugging it all

Types in PHP Variable Types int, float, bool, string array object resource null Comparisons with ==, !=, ===, !== 1 == "1" is true 1 === "1" is false 1 === 1 is true

Why use PHP? Available nearly everywhere Very good support/documentation Plenty of tools to help Fast development Even has a GUI library!

Advanced Strings Dot (.) is concatenation (not de-reference) $string = "Hello World"; echo 'This is a \n $string'; echo "This is a \n $string"; Outputs: This is a \n $string This is a Hello World

Heredoc/Nowdoc echo <<<AnYtHiNg This expands $variables and \n newlines AnYtHiNg; echo <<<'aNyThInG' This doesn't expand $variables or \n newlines aNyThInG;

Array Handling In Java: Iterable i = new Iterable (); //... for(Clazz c : i){ //i gets looped through and assigned to c at each loop } In PHP $array = array("key1" => "value1", "key2" => "value2"); foreach($array as $key => $value){ //$key is the index/key, and $value is the value }

Array Handling cont. Array constructor: $array = array("item", "key1" => 1, "key2" => "value"); $array[] = "value1"; $array[] = "value2"; //equivalent to $array = array("value1", "value2"); //or $array[0] = "value1"; $array[1] = "value2";

$_REQUEST $_REQUEST is equivalent to: array_merge($_GET, $_POST, $_COOKIES); Order can be arranged in the php.ini file

DON'T USE EXTRACT ON USER INPUT! (use $_REQUEST instead) Example

Quicker file handling $file_contents_as_string = file_get_contents($filename) file_put_contents($filename, $contents_to_write)

The Session session_start() sends user PHPSESSID cookie. $_SESSION holds only this user's data First script: $_SESSION['key'] = $value; Second script: $value = $_SESSION['key'];

Includes/Requires file.php: $var = "Hello World!"; page.php: $var = "Goodbye World!"; include("file.php"); echo $var; Outputs: Hello World!

Variable Scope In Java: String s = "Hi"; if(true){ System.out.println(s); } System.out.println(s); This works fine

Variable Scope (cont.) In Java: if(true){ String a = "Hello World"; } System.out.println(a); Compile error!

Variable Scope (cont.) In PHP: $string = "Hi"; if(true){ echo $string; } Outputs: Hi

Variable Scope (cont.) In PHP: if(true){ $string = "Hi"; } echo $string; Outputs: Hi (not a syntax error!)

Variable Scope (cont.) Two scopes: Global Scope - all variables outside of a function Function Scope - only variables declared in function $a = "Hi!"; function f(){ echo isset($a)?"It is set!":"It is not set!"; } f(); Outputs: It is not set!

Variable Scope (cont.) Superglobals: $_GET, $_POST, $_SESSION, etc... always in scope. Use the global keyword $a = "Hi!"; function f(){ global $a; echo isset($a)?"It is set!":"It is not set!"; } f(); Outputs: "It is set!"

Functions In Java: class myClass{ int myFunction(int one, String two){ //do stuff } int myFunction(int one){ return myFunction(one, "default"); } Perfectly legitimate Java code

Functions (cont.) In PHP: function myFunction($one, $two = "default"){ //do something; }

Functions (cont.) In Java: class myClass{ int myFunction(int one, boolean two){ return something; } int myFunction(boolean two, int one){ return something; } } No equivalent in PHP

HTTP Sample HTTP request POST /index.php HTTP/1.1 Host: example.com Content-Type: application/x-www-form-urlencoded key1=value1&key2=value%20of%20key2

HTTP (cont.) Sample HTTP Response HTTP/ OK Date: Mon, 07 Mar :05:05 GMT Content-Type: text/html Content-Length: x... Example in BurpSuite

CSS Cascading Style Sheets Order of priority:

CSS (cont.) Selectors: E - element E #id - element with id='id'.class - element with class='class' E > F - element F that is child of E E F - element F that is descendant of E div.red { color: red; }

CSS (cont.) Syntax: { : ; }

Javascript Client Side Scripting Server forms the html Javascript manipulates that html AJAX used to communicate Install JQuery, and use it

PHP + HTTP + CSS + Javascript

Debugging everything Use Firebug/Chrome Developer Tools See all parts of the HTTP transaction Debug Javascript Edit HTML realtime Watch GET/POST requests live Example

Sources php.net - PHPs equivalent to Java API w3schools.com - Javascript/CSS/HTML reference jQuery.com - Javascript wrapper library portswigger.net/burp/ - BurpSuite - Firebug for Firefox