Web Programming with PHP

Similar documents
Web Application Development (WAD) V th Sem BBAITM(Unit-1) By: Binit Patel

PHP. MIT 6.470, IAP 2010 Yafim Landa

Database Systems Fundamentals

Security issues. Unit 27 Web Server Scripting Extended Diploma in ICT 2016 Lecture: Phil Smith

Web Server Setup Guide

Ampliación de Bases de Datos

Multimedia im Netz Online Multimedia Winter semester 2015/16. Tutorial 03 Minor Subject

This slide shows the OWASP Top 10 Web Application Security Risks of 2017, which is a list of the currently most dangerous web vulnerabilities in

Introduction. Server-side Techniques. Introduction. 2 modes in the PHP processor:

CSCE 548 Building Secure Software SQL Injection Attack

PHP-security Software lifecycle General Security Webserver security PHP security. Security Summary. Server-Side Web Languages

Managing State. Chapter 13

You can also set the expiration time of the cookie in another way. It may be easier than using seconds.

Lab 4: Basic PHP Tutorial, Part 2

(Frequently Asked Questions)

Surveyor Getting Started Guide

WEB SECURITY WORKSHOP TEXSAW Presented by Solomon Boyd and Jiayang Wang

GET /index.php HTTP/1.1 Host: User- agent: Mozilla/4.0

Some things to watch out for when using PHP and Javascript when building websites

UNIT-VI CREATING AND USING FORMS

Joomla 3.X Global Settings Part III Server Settings

PHP 5 if...else...elseif Statements

PHP 1. Introduction Temasek Polytechnic

By the end of this section of the practical, the students should be able to:

PHP. Lab. de Bases de Dados e Aplicações Web MIEIC, FEUP 2010/11. Sérgio Nunes

John Coggeshall Copyright 2006, Zend Technologies Inc.

We want to install putty, an ssh client on the laptops. In the web browser goto:

Chapter 9. Managing State Information. Understanding State Information (continued) Understanding State Information 10/29/2011.

COGNOS (R) ENTERPRISE BI SERIES COGNOS REPORTNET (TM)

Lecture 7: Dates/Times & Sessions. CS 383 Web Development II Wednesday, February 14, 2018

HTML 5 Form Processing

Introduction to Web Mining for Social Scientists Lecture 4: Web Scraping Workshop Prof. Dr. Ulrich Matter (University of St. Gallen) 10/10/2018

Instructor s Notes Web Data Management Web Client/Server Concepts. Web Data Management Web Client/Server Concepts

How to use your Participant Center for fundraising success! How to: Login

Your leads. Your way. Lead delivery options for BuyerZone clients and partners.

LucidWorks: Searching with curl October 1, 2012

The Weakest Link: Mitigating Web Application Vulnerabilities. webscurity White Paper. webscurity Inc. Minneapolis, Minnesota USA

Reflected XSS Cross-Site Request Forgery Other Attacks

Working with Pages... 9 Edit a Page... 9 Add a Page... 9 Delete a Page Approve a Page... 10

The PHP language. Teaching you everything about PHP? Not exactly Goal: teach you how to interact with a database via web

DATABASE SYSTEMS. Introduction to web programming. Database Systems Course, 2016

PHP and MySQL Programming

Building a Web-based Health Promotion Database

Lecture 3: Web Servers / PHP and Apache. CS 383 Web Development II Monday, January 29, 2018

A Server- and Browser-Transparent CSRF Defense for Web 2.0 Applications

Installing PHP on Windows 10 Bash and Starting a Local Server

Senior Technical Specialist, IBM. Charles Price (Primary) Advisory Software Engineer, IBM. Matthias Falkenberg DX Development Team Lead, IBM

Chapter 7:- PHP. Compiled By:- Sanjay Patel Assistant Professor, SVBIT.

Web Application Security. Philippe Bogaerts

WEB SECURITY: XSS & CSRF

WEB APPLICATION ENGINEERING II

Lies, Damned Lies, Statistics and SQL

Basic, Step-by-Step Installation Manual

Hello everyone! Page 1. Your folder should look like this. To start with Run your XAMPP app and start your Apache and MySQL.

Writing Perl Programs using Control Structures Worked Examples

Inside the PostgreSQL Shared Buffer Cache

BrownNow A Current Events Application for Brown University. Craig Hawkins Advisor: Stan Zdonik Masters Project Report, Brown University 2017

What is PHP? [1] Figure 1 [1]

COMP519 Web Programming Lecture 28: PHP (Part 4) Handouts

L.A.M.P. Stack Part I

A QUICK GUIDE TO PROGRAMMING FOR THE WEB. ssh (then type your UBIT password when prompted)

WEB SECURITY: WEB BACKGROUND

Programming Assignment 3

Web Security: Vulnerabilities & Attacks

Electric Paoge. Browser Scripting with imacros in Illuminate

P2P Programming Assignment

MythoLogic: problems and their solutions in the evolution of a project

Note about compatibility: This module requires that PHP is enabled on the server. You should verify that your host offers PHP prior to installation.

ORB Education Quality Teaching Resources

Release Presentation. ODS Web Services Version Open Data Services Via Web Services. Release Date: 2014/09/30

java -jar Xmx2048mb /Applications/burpsuite_pro_v1.5.jar

9 th CA 2E/CA Plex Worldwide Developer Conference 1

Setting up a LAMP server

An Introduction to JavaScript & Bootstrap Basic concept used in responsive website development Form Validation Creating templates

P2_L12 Web Security Page 1

A Web-Based Introduction

Web Attacks CMSC 414. September 25 & 27, 2017

Bluehost and WordPress

Table of contents. Pure ASP Upload 3 Manual DMXzone

ST. XAVIER S COLLEGE (Affiliated to Tribhuvan University) Maitighar, Kathmandu NET CENTRIC COMPUTING [CSC 360]

Lecture 12. PHP. cp476 PHP

SmartList Senior Project Paper

PIC 40A. Lecture 19: PHP Form handling, session variables and regular expressions. Copyright 2011 Jukka Virtanen UCLA 1 05/25/12

ITS331 IT Laboratory I: (Laboratory #11) Session Handling

PHP by Pearson Education, Inc. All Rights Reserved.

Jackson State University Department of Computer Science CSC / Advanced Information Security Spring 2013 Lab Project # 3

web.py Tutorial Tom Kelliher, CS 317 This tutorial is the tutorial from the web.py web site, with a few revisions for our local environment.

WEBD 236 Lab 5. Problem

Web Security IV: Cross-Site Attacks

CHAPTER 7 WEB SERVERS AND WEB BROWSERS

help.gorgias.io Documentation

CHAPTER 2. Troubleshooting CGI Scripts

This takes you to the System Administration page, from which you create and edit guides and customize your profile:

Web Security. Jace Baker, Nick Ramos, Hugo Espiritu, Andrew Le

Apache, Php, MySql Configuration

Basic Uses of JavaScript: Modifying Existing Scripts

Setting Up the Development Environment

Lecture 4. Wednesday, January 27, 2016

Beginning HTML. The Nuts and Bolts of building Web pages.

Fachgebiet Technische Informatik, Joachim Zumbrägel

Transcription:

We know that we can use HTML to build websites, but websites built using pure HTML suffer from a serious limitation. Imagine we want to create a website that displays the current time in Cambridge, MA, displaying it to the latest minute.

<html> <head> <title>current Time in Cambridge</title> </head> <body> The current time in Cambridge is 14:08 </body> </html>

<html> <head> <title>current Time in Cambridge</title> </head> <body> The current time in Cambridge is 14:09 </body> </html>

<html> <head> <title>current Time in Cambridge</title> </head> <body> The current time in Cambridge is 14:10 </body> </html>

<html> <head> <title>current Time in Cambridge</title> </head> <body> The current time in Cambridge is 14:11 </body> </html>

Websites that are pure HTML are completely static. The only way we can update the content of our pages is to manually open up our source files, edit and save, and then the next time the user visits or refreshes the page they ll get the content. Incorporating PHP into our code can make our code quite a bit more flexible and introduce a way for our pages to update or be dynamic without requiring our intervention.

To run an instance of Apache (a popular web server with the capacity to interpret PHP), simply create a directory where you would like your pages to live and then run the command apache50 start /path/to/dir

To test that your Apache server is configured correctly, here s a common equivalent of hello, world for PHP web programming: <?php phpinfo();?>

<?php date_default_timezone_set( US/Eastern ); $time = date( H:i:s, time());?> <html> <head> <title>current Time in Cambridge</title> </head> <body> The current time in Cambridge is <?= $time?>. </body> </html>

<?php date_default_timezone_set( US/Eastern ); $time = date( H:i:s, time());?> <html> <head> <title>current Time in Cambridge</title> </head> <body> The current time in Cambridge is <?= $time?>. </body> </html>

Because the PHP interpreter ignores everything that is not inside of the PHP delimiters, that means that we can intersperse HTML and PHP without any problems, only using PHP for those parts of our website that require dynamism, and letting the static information remain the same. Why is it advantageous for us to do this? Instead of putting everything inside of the PHP delimiters and printing out HTML?

There s not too much to writing PHP code for the web that s different from writing it for the command line so far. What if we want to pass information between files that we have on our PHP server? Or what if we want to allow the user to pass information into our web pages? PHP supports a number of special superglobal variables to accomplish this.

$_GET $_GET is perhaps the simplest of these superglobal variables for passing data between PHP files or allowing the user to supply your PHP page with data. With this technique, we scrape data supplied at the URL which is stored in a query string consisting of key-value pairs, which are then stored in the $_GET associative array.

<?php?> foreach($_get as $key => $value) { print( <p>{$key}: {$value}</p> ); }

$_GET Can you envision one possible issue with the $_GET superglobal?

$_GET Can you envision one possible issue with the $_GET superglobal? http://localhost/get3.php?name=doug&pw=squadgoals

$_GET Can you envision one possible issue with the $_GET superglobal? http://localhost/get3.php?name=doug&pw=squadgoals

$_GET Can you envision one possible issue with the $_GET superglobal? $_GET is great for getting information to the page quickly, but can be problematic for passing sensitive information, as it makes it very easy for an attacker (or someone less malicious) to easily see that sensitive information.

$_POST $_POST is an alternative method for transmitting data between pages or allowing users to send information that most frequently comes up in the context of HTML forms. Though information can be sent via HTML forms with the GET method, too! Unlike $_GET, using this technique submits user information inside of the HTTP headers, instead of via the URL.

<html> <head> <title>posting Form</title> </head> <body> <form action= post.php method= post > <input name= name type= text /> <input name= pw type= password /> <input type= submit /> </form> </body> </html>

<html> <head> <title>posting Form</title> </head> <body> <form action= post.php method= post > <input name= name type= text /> <input name= pw type= password /> <input type= submit /> </form> </body> </html>

<html> <head> <title>posting Form</title> </head> <body> <form action= post.php method= post > <input name= name type= text /> <input name= pw type= password /> <input type= submit /> </form> </body> </html>

<html> <head> <title>posting Form</title> </head> <body> <form action= post.php method= post > <input name= name type= text /> <input name= pw type= password /> <input type= submit /> </form> </body> </html>

<?php echo( <p>. $_POST[ name ]. </p> ); echo( <p>. $_POST[ pw ]. </p> );?>

<?php echo( <p>. $_POST[ name ]. </p> ); echo( <p>. $_POST[ pw ]. </p> );?>

At-home exercise Create a pair of web pages: The first, a simple form with a single field and a submit button. The second, which is expecting input from the form via the POST method and based on the input creates an n-by-n multiplication, where n is a number the user submits through the form. No need to do any error checking. You can assume the user is not malicious and will always input a reasonably-small value.

$_SESSION $_SESSION is one additional superglobal that PHP provides to store data that you d like to be available across multiple pages so long as a user is logged in to your website, so that you don t have to repeatedly pass information via $_POST. After you create a session with the PHP function session_start(), you can use and modify $_SESSION across your site and its contents will not be lost until you session_destroy().

Writing fairly dynamic websites with PHP drastically improves your site s quality without requiring too much additional complexity. Practice, practice, practice! You already know the basics from your experience with C, now you re just applying those basics with a slightly different language and in a slightly different context. Don t be afraid to look things up on the internet! php.net, for example, is a fantastic resource for PHP s documentation!