Online Multimedia Winter semester 2015/16



Similar documents
Multimedia im Netz Online Multimedia Winter semester 2015/16. Tutorial 03 Major Subject

Role Based Access Control. Using PHP Sessions

<?php if (Login::isLogged(Login::$_login_front)) { Helper::redirect(Login::$_dashboard_front); }

SEEM4540 Open Systems for E-Commerce Lecture 06 Online Payment

Facebook Twitter YouTube Google Plus Website

Real SQL Programming 1

Introduction to Server-Side Programming. Charles Liu

c. Write a JavaScript statement to print out as an alert box the value of the third Radio button (whether or not selected) in the second form.

Working with forms in PHP

Short notes on webpage programming languages

Advanced Tornado TWENTYONE Advanced Tornado Accessing MySQL from Python LAB

Topic 7: Back-End Form Processing and Database Publishing with PHP/MySQL

A table is a collection of related data entries and it consists of columns and rows.

Mul$media im Netz (Online Mul$media) Wintersemester 2014/15. Übung 03 (Nebenfach)

DIPLOMA IN WEBDEVELOPMENT

PHP Authentication Schemes

Chapter 22 How to send and access other web sites

Hello World RESTful web service tutorial

A Brief Introduction to MySQL

JavaScript Basics & HTML DOM. Sang Shin Java Technology Architect Sun Microsystems, Inc. sang.shin@sun.com

INSTALLING, CONFIGURING, AND DEVELOPING WITH XAMPP

UQC103S1 UFCE Systems Development. uqc103s/ufce PHP-mySQL 1

COURSE CONTENT FOR WINTER TRAINING ON Web Development using PHP & MySql

WEB DEVELOPMENT COURSE (PHP/ MYSQL)

Contents. 2 Alfresco API Version 1.0

Zend Framework Database Access

PHP Tutorial From beginner to master

CS412 Interactive Lab Creating a Simple Web Form

JavaScript By: A. Mousavi & P. Broomhead SERG, School of Engineering Design, Brunel University, UK

An Introduction to Developing ez Publish Extensions

Course Outline Basic Web Development

Secure Application Development with the Zend Framework

By : Ashish Modi. CRUD USING PHP (Create, Read, Update and Delete on Database) Create Database and Table using following Sql Syntax.

IE Class Web Design Curriculum

Advanced Web Technology 10) XSS, CSRF and SQL Injection 2

Further web design: HTML forms

<Insert Picture Here>

Topics. Database Essential Concepts. What s s a Good Database System? Using Database Software. Using Database Software. Types of Database Programs

Advanced Object Oriented Database access using PDO. Marcus Börger

Certified PHP/MySQL Web Developer Course

Q&A for Zend Framework Database Access

COURSE SYLLABUS EDG 6931: Designing Integrated Media Environments 2 Educational Technology Program University of Florida

Script Handbook for Interactive Scientific Website Building

2- Forms and JavaScript Course: Developing web- based applica<ons

A SQL Injection : Internal Investigation of Injection, Detection and Prevention of SQL Injection Attacks

Chapter 2: Interactive Web Applications

Web Development 1 A4 Project Description Web Architecture

pset 7: C$50 Finance Zamyla Chan

JavaScript and Dreamweaver Examples

Website Login Integration

LAB MANUAL CS (22): Web Technology

LAMP [Linux. Apache. MySQL. PHP] Industrial Implementations Module Description

Web Development using PHP (WD_PHP) Duration 1.5 months

Chapter 2: Interactive Web Applications

Getting Started with AWS. Hosting a Static Website

1. What is SQL Injection?

MERCHANT INTEGRATION GUIDE. Version 2.8

LAB 1: Getting started with WebMatrix. Introduction. Creating a new database. M1G505190: Introduction to Database Development

database abstraction layer database abstraction layers in PHP Lukas Smith BackendMedia

INFORMATION BROCHURE Certificate Course in Web Design Using PHP/MySQL

SQL Injection Attack Lab Using Collabtive

Online shopping store

Sample HP OO Web Application

RARITAN VALLEY COMMUNITY COLLEGE ACADEMIC COURSE OUTLINE CISY 233 INTRODUCTION TO PHP

Best Practices For PL/SQL Development in Oracle Application Express

LICENSE4J AUTO LICENSE GENERATION AND ACTIVATION SERVER USER GUIDE

E-Commerce: Designing And Creating An Online Store

Website Planning Checklist

HTML Tables. IT 3203 Introduction to Web Development

Web Application Guidelines

FileMaker for PHP Developers

Thursday, February 7, DOM via PHP

SQL Injection. Blossom Hands-on exercises for computer forensics and security

Configuring iplanet 6.0 Web Server For SSL and non-ssl Redirect

In order for the form to process and send correctly the follow objects must be in the form tag.

SQL Injection. The ability to inject SQL commands into the database engine through an existing application

Building Rich Internet Applications with PHP and Zend Framework

Brainshark/Salesforce.com Integration Installation Procedures

Internet Technologies

Abusing HTML5. DEF CON 19 Ming Chow Lecturer, Department of Computer Science TuCs University Medford, MA

SQL Injection. SQL Injection. CSCI 4971 Secure Software Principles. Rensselaer Polytechnic Institute. Spring

Programming Autodesk PLM 360 Using REST. Doug Redmond Software Engineer, Autodesk

Best Practices for Dynamic SQL

Application Security

Connecting to a Database Using PHP. Prof. Jim Whitehead CMPS 183, Spring 2006 May 15, 2006

CS3051: Digital Content Management

Designing for Dynamic Content

Concepts Design Basics Command-line MySQL Security Loophole

How To Save Data On A Spreadsheet

Tutorial: Using PHP, SOAP and WSDL Technology to access a public web service.

Transcription:

Multimedia im Netz Online Multimedia Winter semester 2015/16 Tutorial 04 Major Subject Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-1

Today s Agenda Repetition: Sessions: Powerpoint Karaoke Discussion of Assignment 03 Database access through PHP & MySQL Break Out: Music Library Management app Quiz Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-2

PHP Sessions: Powerpoint Karoake Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-3

Sessions with PHP Sessions need to be started before any output occurs Create session ID cookie: session_start() Delete the session ID cookie: session_destroy() Read / write session values: superglobal $_SESSION array immediately reset session like this $_SESSION = array(); Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-4

Example: Counting visits <?php session_start();?> <!DOCTYPE html> <html> [...] <body> <?php if(!isset($_session['count'])){ $_SESSION['count'] = 1; } else{ $_SESSION['count']++; } echo '<p>current count: '.$_SESSION['count'].'</p>';?> </body></html> Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-5

Example: Destroying Sessions <?php session_start();?> <!DOCTYPE html> <html> [...] <body> <?php if(isset($_post['destroy'])) { session_destroy(); $_SESSION = array(); } if(!isset($_session['count'])){ $_SESSION['count'] = 1; } else{ $_SESSION['count']++; } echo '<p>current count: '.$_SESSION['count'].'</p>';?> <form method="post"> <input type="submit" name="destroy" value="reset"/> </form> </body> </html> Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-6

Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-7

Persistent Data Storage: PHP & MySQL Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-8

PHP & MySQL Multiple functions and APIs available for PHP to work with databases: mysql ( Deprecated since PHP 5.5.0) mysqli (i is for improved ) PDO (PHP Data Objects) mysql is still supported for older PHP versions It is highly recommendable to use mysqli or PDO Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-9

MySQL at the CIP-Pool Access Datenbank Management here: https://tools.rz.ifi.lmu.de/ Create a new account (required) Create a new database (required) Connect to db2.cip.ifi.lmu.de Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-10

Test Connection <?php $c = mysql_connect("localhost", "user", "password");?> if($c){ echo "Connection to database has been established."; } else { echo "Could not connect to database"; } Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-11

Mysqli i stands for improved Offers two interfaces Procedural (traditional) Object-oriented (see lecture slides) Supports : prepared statements multiple statements within one query transactions Improved debugging tools Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-14

Mysqli (procedural) Establish connection $c = mysqli_connect("localhost", "user", "password", "mydb"); Select database mysqli_select_db($c,"mydb"); Close connection mysqli_close($c); PHP statement for MySQL query $results = mysqli_query($c, $query); Process the results: mysqli_fetch_array($results); mysqli_fetch_array($results, MYSQLI_NUM); mysqli_fetch_array($results, MYSQLI_ASSOC); Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-15

Mysqli (object oriented) Establish connection $c = new mysqli("host","user","password","db"); PHP statement for MySQL query $results = $c->query($query); Process the results $results->fetch_assoc(); $results->fetch_row(); $results->fetch_all(mysqli_both); $results->fetch_all(mysqli_assoc); $results->fetch_all(mysqli_num); Close the connection $c->close(); Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-16

Mysqli: Prepared Statements (I) Separate structure and data through the use of wildcards. In the query we use? as wildcards Advantages: You can reuse the query with different parameters More secure (cf. SQL Injections) How to do it: Prepare : Prepare the query. The template is checked for errors an. Bind : Bind the parameters to the wildcards Execute : The query is executed with the passes parameters Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-17

Mysqli: Prepared Statements (II) Query with wildcards $query = "SELECT lastname FROM people WHERE firstname=?"; Create the statement $statement = $c->prepare($query); Bind the parameters $name = "Sam"; $statement->bind_param("s", $name); Execute the query $statement->execute(); Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-18

Mysqli: Prepared Statements (III) Bind result columns to variables $statement->bind_result($lastnameresults); Fetch results $statement->fetch(); Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-19

Example: Prepared Statements <?php include_once('connectioninfo.php'); $c = new mysqli($host,$user,$password,$db); $query = "SELECT lastname FROM people WHERE firstname=?"; $statement = $c->prepare($query); $name = "Sam"; $statement->bind_param("s", $name); $statement->execute(); $statement->bind_result($lastnameresults); while($statement->fetch()){ print_r($lastnameresults); echo "<br />"; } Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-20

Password Hashing in PHP (I) PHP has built-in password hashing functions password_hash() password_verify()... Don t store plain text passwords in databases. Ever ;) Advantages of password_hash() and password_verify(): More secure Easy to use Disadvantages: only available with PHP >= 5.5.0 Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-22

Password Hashing in PHP (II) Hashing a password: $pwhash = password_hash("password1234",password_default); Verifying a hash: if (password_verify("password1234", $pwhash)) { echo "Your password is correct"; } Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-23

Break-Out Task Create a music library management tool Allow users to create artist & album entries There is a code skeleton on GitHub: https://github.com/mimuc-mmn/tutorials-15-16/tree/master/tutorial04/breakout Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-24

After an insert Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-25

If you have time Allow deleting the entries Avoid duplicates Create additional optional fields for runtime, track count, buying link etc. Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-26

Round-up Quiz 1. Name an advantage of mysqli over the deprecated mysql. 2. What does mysqli->fetch_assoc() do? 3. Why is it recommendable to call mysqli->close? 4. What is an advantage of prepared statements? 5. What are the steps of working with prepared statements? Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-27

Thanks! What are your questions? Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-28

Let s begin with the Assignment! Download the assignment sheet Start with task 1 You can collaborate with your neighbor Turn in the assignment by November 9 th, 12:00 noon via UniWorX Ludwig-Maximilians-Universität München Online Multimedia WS 2015/16 - Tutorial 04-29