PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

Session 1 & 2BBK P1 Module5-May-2007 : [‹#›] PHP: The Basics.
PHP for Server-Side Preprocessing Chapter 08. Overview and Objectives Present a brief history of the PHP language Discuss how PHP fits into the overall.
Server-Side vs. Client-Side Scripting Languages
IST 221 Internet Concepts and Applications Introduction to PHP.
B.Sc. Multimedia ComputingMedia Technologies Database Technologies.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Computer Science 101 Web Access to Databases Overview of Web Access to Databases.
Server & Client  Client: Your computer  Server: Powerful & Expensive computer. Requires network access.
1 CS428 Web Engineering Lecture 18 Introduction (PHP - I)
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
PHP Workshop ‹#› PHP: The Basics. PHP Workshop ‹#› What is it? PHP is a scripting language commonly used on web servers. –Stands for “PHP: Hypertext Preprocessor”
Sys Prog & Scripting - HW Univ1 Systems Programming & Scripting Lecture 15: PHP Introduction.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
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.
PHP : Hypertext Preprocessor
Databases with PHP A quick introduction. Y’all know SQL and Databases  You put data in  You get data out  You can do processing on it very easily 
PHP - Hypertext Preprocessor. Introduction PHP is a powerful server-side scripting language for creating dynamic and interactive websites. PHP is a powerful.
SCV1223 PHP - Hypertext Preprocessor. Introduction PHP is a powerful server-side scripting language for creating dynamic and interactive websites. PHP.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
PHP Hypertext PreProcessor. Documentation Available SAMS books O’Reilly Books.
IDK0040 Võrgurakendused I harjutus 06: PHP: Introduction Deniss Kumlander.
Web Server Administration Chapter 7 Installing and Testing a Programming Environment.
Server & Client  Client: Your computer  Server: Powerful & Expensive computer. Requires network access.
Accessing MySQL with PHP IDIA 618 Fall 2014 Bridget M. Blodgett.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Lecture 8 – Cookies & Sessions SFDV3011 – Advanced Web Development 1.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
Intro to DatabasesClass 4 SQL REVIEW To talk to the database, you have to use SQL SQL is used by many databases, not just MySQL. SQL stands for Structured.
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.
Introduction to PHP Advanced Database System Lab no.1.
CS 4720 Dynamic Web Applications CS 4720 – Web & Mobile Systems.
SQL INJECTIONS Presented By: Eloy Viteri. What is SQL Injection An SQL injection attack is executed when a web page allows users to enter text into a.
David Lawrence 7/8/091Intro. to PHP -- David Lawrence.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
Web Security Lesson Summary ●Overview of Web and security vulnerabilities ●Cross Site Scripting ●Cross Site Request Forgery ●SQL Injection.
SESSIONS 27/2/12 Lecture 8. ? Operator Similar to the if statement but returns a value derived from one of two expressions by a colon. Syntax: (expression)
1) PHP – Personal Home Page Scripting Language 2) JavaScript.
Introduction to PHP Brendan Knight. What is PHP PHP is a general-purpose scripting language originally designed for web development to produce dynamic.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
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.
Unit-6 Handling Sessions and Cookies. Concept of Session Session values are store in server side not in user’s machine. A session is available as long.
Session 11: Cookies, Sessions ans Security iNET Academy Open Source Web Development.
PHP Overview. What is PHP Widely available scripting language Free Alternative to Microsoft’s ASP Runs on the Web Server; not in the browser Example:
1 Server Side scripting PHP. 2 What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are.
Web Security (cont.) 1. Referral issues r HTTP referer (originally referrer) – HTTP header that designates calling resource  Page on which a link is.
Web Database Programming Using PHP
PHP (Session 2) INFO 257 Supplement.
Introduction to Dynamic Web Programming
Web Database Programming Using PHP
PHP Hypertext Preprocessor
PHP / MySQL Introduction
BASIC PHP and MYSQL Edward S. Flores.
PHP Introduction.
PHP Overview PHP: Hypertext Preprocessor Server-Side Scripting
ISC440: Web Programming 2 Server-side Scripting PHP 3
Web Systems Development (CSC-215)
PHP: Security issues FdSc Module 109 Server side scripting and
Web Systems Development (CSC-215)
Web DB Programming: PHP
Web Programming Language
Tutorial 6 PHP & MySQL Li Xu
PHP an introduction.
Hypertext Preprocessor
Presentation transcript:

PHP Hypertext Preprocessor Information Systems 337 Prof. Harry Plantinga

Getting Nice Output We’ve been talking mainly about functionality of web sites We’ve been talking mainly about functionality of web sites Many major sites differ mainly in looks Many major sites differ mainly in looks Theme system formats output Theme system formats output To understand the theme system and to make your own modules requires PHP To understand the theme system and to make your own modules requires PHP

PHP Overview What is it? What is it? PHP Hypertext Preprocessor PHP Hypertext Preprocessor Server-side scripting language Server-side scripting language Alternative to e.g. Microsoft’s ASP Alternative to e.g. Microsoft’s ASP Widely used, cross-platform, free Widely used, cross-platform, free PHP files contain PHP files contain HTML HTML PHP code PHP code

PHP Example MSPSP U14 Boys Classic 3 <?php $result = db_query("select name, abbrev, wins, losses, ties, points, goalsFor, goalsAgainst, power from stats.team order by points desc, power desc"); while ($row = db_fetch_array($result)) { echo(" $row[name] "); echo(" $row[wins] "); echo(" $row[losses] "); echo(" $row[ties] "); echo(" $row[points] "); echo(" $row[goalsFor] "); echo(" $row[goalsAgainst] "); $power=round($row[power],2); echo(" $power "); } ?>

PHP Basics /* comments */ /* comments */ Variables: loosely typed Variables: loosely typed $var1 = "hello world"; $var2 = 7; C/Java/JavaScript-like syntax for expressions, arrays, if, for, while, switch, etc C/Java/JavaScript-like syntax for expressions, arrays, if, for, while, switch, etc Associative arrays, concatenation like perl: $mascot('calvin')='knight'; $mascot('hope') = 'flying'. ' dutchman'; Associative arrays, concatenation like perl: $mascot('calvin')='knight'; $mascot('hope') = 'flying'. ' dutchman'; functions: function add($a, $b) { return $a + $b; } functions: function add($a, $b) { return $a + $b; }

Question How would I write PHP to Display "Hello world!" Display "Hello world!" Hello world! "); ?> Hello world! "); ?> Display … 100 Display … 100<?php for ($i=1; $i<=100; $i++) echo("$i "); ?> Display the current date Display the current date Load in a server side include file Load in a server side include file

Question How can you read and use data entered into a form? How can you read and use data entered into a form?

PHP Forms Handling Forms handling, GET and POST Forms handling, GET and POST hello.html hello.html Name: Name: </form> hello.php hello.php<html> Welcome, ! Welcome, ! </html> Also, $_GET["attname"] (example) Also, $_GET["attname"] (example)example

Question How can you keep track of a user's preferences for your website, say preferred font size? How can you keep track of a user's preferences for your website, say preferred font size?

Cookies Built-in cookie handling: setcookie(name, value, expire, path, domain); $expire = time() + 60*60*24*365; setcookie("fontsize","120%",$expire); Built-in cookie handling: setcookie(name, value, expire, path, domain); $expire = time() + 60*60*24*365; setcookie("fontsize","120%",$expire); Retrieve a cookie: echo $_COOKIE["fontsize"]; Retrieve a cookie: echo $_COOKIE["fontsize"]; Example Example Example

Sessions Session variables are a convenient way to keep track of users over different pageviews Session variables are a convenient way to keep track of users over different pageviews Kept as a cookie or propagated in the URL Kept as a cookie or propagated in the URL Starting a session: … Starting a session: … Storing a session variable: Storing a session variable:

"We've received your ; someone will get back to you soon…" "We've received your ; someone will get back to you soon…" <?php $to = $from = $subject = "Good job!"; $message = "Just wanted to say…"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?>

Database access Example <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) die('Could not connect: '. mysql_error()); Example <?php $con = mysql_connect("localhost","peter","abc123"); if (!$con) die('Could not connect: '. mysql_error()); mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons"); while($row = mysql_fetch_array($result)) { echo $row["FirstName"]." ". $row["LastName"]; echo " "; } mysql_close($con); ?> mysql_select_db("my_db", $con); $result = mysql_query("SELECT * FROM Persons"); while($row = mysql_fetch_array($result)) { echo $row["FirstName"]." ". $row["LastName"]; echo " "; } mysql_close($con); ?>

A Test… What happens if I log in to a server with the username hi' or 1=1— What happens if I log in to a server with the username hi' or 1=1— How about something like this? UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='admin_login'— How about something like this? UNION SELECT TOP 1 COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='admin_login'— Called an SQL Injection attack Called an SQL Injection attackSQL Injection attackSQL Injection attack How to prevent? How to prevent?

Input filtering Make sure input values are valid and safe Make sure input values are valid and safe ALWAYS FILTER ALL INPUT DATA! ALWAYS FILTER ALL INPUT DATA! Example Example

Sanitizing filters Sanitizing filters: remove harmful content Sanitizing filters: remove harmful content FILTER_SANITIZE_STRING, …ENCODED, …SPECIAL_CHARS, …EMAL, …URL, …NUMBER_INT, …MAGIC_QUOTES [apply addslashes()] FILTER_SANITIZE_STRING, …ENCODED, …SPECIAL_CHARS, …EMAL, …URL, …NUMBER_INT, …MAGIC_QUOTES [apply addslashes()] Validation filters Validation filters FILTER_VALIDATE_INT, BOOLEAN, FLOAT, REGEXP, URL, , IP FILTER_VALIDATE_INT, BOOLEAN, FLOAT, REGEXP, URL, , IP

Ethical responsibility… How common are these attacks? How common are these attacks?common Do you have any ethical responsibilities here? Do you have any ethical responsibilities here?