Motivation retaining redisplaying



Similar documents
CPSC Network Programming. , FTP, and NAT.

FTP and . Computer Networks. FTP: the file transfer protocol

Bld. du Roi Albert II, 27, B 1030 BRUSSELS Tel Fax Secure file upload in PHP web applications

Working with forms in PHP

HTML Forms and CONTROLS

PHP Tutorial From beginner to master

. Daniel Zappala. CS 460 Computer Networking Brigham Young University

Chapter 2 Application Layer. Lecture 5 FTP, Mail. Computer Networking: A Top Down Approach

PHP Form Handling. Prof. Jim Whitehead CMPS 183 Spring 2006 May 3, 2006

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

CSCI-1680 SMTP Chen Avin

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

Chapter 22 How to send and access other web sites

Network Services. SMTP, Internet Message Format. Johann Oberleitner SS 2006

Internet Technologies

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.

Chapter 2: Interactive Web Applications

1 Introduction: Network Applications

Contents. 2 Alfresco API Version 1.0

Internet Technologies. World Wide Web (WWW) Proxy Server Network Address Translator (NAT)

Script Handbook for Interactive Scientific Website Building

This script is called by an HTML form using the POST command with this file as the action. Example: <FORM METHOD="POST" ACTION="formhandler.

PHP Authentication Schemes

Website Login Integration

Evolution of the WWW. Communication in the WWW. WWW, HTML, URL and HTTP. HTTP Abstract Message Format. The Client/Server model is used:

Internet Technology 2/13/2013

Evolution of the WWW. Communication in the WWW. WWW, HTML, URL and HTTP. HTTP - Message Format. The Client/Server model is used:

TCP/IP Networking, Part 2: Web-Based Control

Intell-a-Keeper Reporting System Technical Programming Guide. Tracking your Bookings without going Nuts!

Protocolo FTP. FTP: Active Mode. FTP: Active Mode. FTP: Active Mode. FTP: the file transfer protocol. Separate control, data connections

CTIS 256 Web Technologies II. Week # 1 Serkan GENÇ

Dynamic Content. Dynamic Web Content: HTML Forms CGI Web Servers and HTTP

Why File Upload Forms are a Major Security Threat

FTP: the file transfer protocol

Package sendmailr. February 20, 2015

Installation Instructions

Perl/CGI. CS 299 Web Programming and Design

infilename outfilename signcert privkey headers flags

Electronic Mail

PEAR. PHP Extension and Application Repository. Mocsnik Norbert Harmadik Magyarországi PHP Konferencia március 12., Budapest

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

FTP: the file transfer protocol

7 Why Use Perl for CGI?

Novell Identity Manager

Now that we have discussed some PHP background

Introduction to Server-Side Programming. Charles Liu

WIRIS quizzes web services Getting started with PHP and Java

JavaScript and Dreamweaver Examples

The Application Layer. CS158a Chris Pollett May 9, 2007.

CS412 Interactive Lab Creating a Simple Web Form

Hello World RESTful web service tutorial

Sending MIME Messages in LISTSERV DISTRIBUTE Jobs

CS43: Computer Networks . Kevin Webb Swarthmore College September 24, 2015

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

HTML Tables. IT 3203 Introduction to Web Development

DATA COMMUNICATOIN NETWORKING

Further web design: HTML forms

Building a Multi-Threaded Web Server

Package httprequest. R topics documented: February 20, 2015

Domain Name System (DNS)

Implementing Specialized Data Capture Applications with InVision Development Tools (Part 2)

2- Electronic Mail (SMTP), File Transfer (FTP), & Remote Logging (TELNET)

PHP Integration Kit. Version User Guide

Viewing Form Results

You can do THAT with SAS Software? Using the socket access method to unite SAS with the Internet

PDG Software. Site Design Guide

Real SQL Programming 1

Networking Applications

Inserting the Form Field In Dreamweaver 4, open a new or existing page. From the Insert menu choose Form.

CSCI110: Examination information.

Management CSCU9B2 CSCU9B2 1

CTF Web Security Training. Engin Kirda

Forms, CGI Objectives. HTML forms. Form example. Form example...

Introduction to LAN/WAN. Application Layer (Part II)

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

Designing for Dynamic Content

# Constructors $smtp = Net::SMTP->new('mailhost'); $smtp = Net::SMTP->new('mailhost', Timeout => 60);

Managed File Transfer with Universal File Mover

2- Electronic Mail (SMTP), File Transfer (FTP), & Remote Logging (TELNET)

# Constructors $smtp = Net::SMTP->new('mailhost'); $smtp = Net::SMTP->new('mailhost', Timeout => 60);

CONTRACT MODEL IPONZ DESIGN SERVICE VERSION 2. Author: Foster Moore Date: 20 September 2011 Document Version: 1.7

Inspiring Creative Fun Ysbrydoledig Creadigol Hwyl. Web Design in Nvu Workbook 1

JWIG Yet Another Framework for Maintainable and Secure Web Applications

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

Online signature API. Terms used in this document. The API in brief. Version 0.20,

THE CHALLENGE OF ADMINISTERING WEBSITES OR APPLICATIONS THAT REQUIRE 24/7 ACCESSIBILITY

Integrating Fax Sending Services

, SNMP, Securing the Web: SSL

Uploaded images filter evasion for carrying out XSS attacks

Understanding Cross Site Scripting

JAVASCRIPT AND COOKIES

RSCCD REMOTE PORTAL TABLE OF CONTENTS: Technology Requirements NOTE

StreamServe Persuasion SP4 Connectors

Transcription:

Motivation When interacting with the user, we need to ensure that the data entered is valid. If an erroneous data is entered in the form, this should be detected and the form should be redisplayed to the user for correction. We don t want to annoy the user by clearing the form and asking for another round of form entry. Therefore a means of retaining and redisplaying form data is required.

Validation Often one needs to test if a critical form element was completed: if ($_POST['strVar'] == NULL){ }... $boovar = 1; if ($boovar) echo Enter Var ;

Validation If all is ok if (!$boovar) && isset($_post[ submit ])) { echo <p>starting calculations... ; } But what if you have 20 elements and just one was missing? Data retention...

Data Retention Create an extra string to store the value $strstorevar = ; //assigned to NULL... if (isset($_post[ submit ]) ) { } if($_post[ strvar ] == NULL){ $boovar = 1; } else { $strstorevar = $_POST[ strvar ]; }

Data Retention <?php $boo_m = 0; $strstore_m = "" ; $boo_n = 0; $strstore_n = "" ; if (isset($_post['submit'])) { if($_post["m"] == NULL) $boo_m = 1; else $strstore_m = $_POST["m"]; if($_post["n"] == NULL) $boo_n = 1; else $strstore_n = $_POST["n"]; if(!($boo_m + $boo_n) && isset($_post["submit"]) ){ $intresult = $_POST['m'] * $_POST['n']; print "The result of ". (int)$_post['m']. " * ". (int)$_post['n']. " = ". } else { if ($boo_m) echo "Please enter a number in the first field. "; if ($boo_n) echo "Please enter a number in the second field. "; } $intresult; } else { echo "This is the first time the page is loaded<br>";}?> <form action='<?php echo $_SERVER["PHP_SELF"];?>' method="post"> <div><label>number 1: <input name="m" size="5" value="<?php echo $strstore_m?>" ></label></div> <div><label>number 2: <input name="n" size="5" value="<?php echo $strstore_n?>" ></label></div> <div><input type="submit" name="submit" value="multiply"></div> </form> <h2>self generating Multiply Using Single PHP file with POST</h2> <?php print "Apache receives the following array: ";print_r($_post)?> See php_retention.php

Automatic php file name extraction predefined <form action='<?php echo $_SERVER["PHP_SELF"];?>' method='get'><p><input type='image' src='squarecircle.gif' name='intimage'/></p> </form>

Image Fields <form action='<?php echo $_SERVER["PHP_SELF"];?>' method='get'><p><input type='image' src='squarecircle.gif' name='intimage'/></p></form> <?php if(isset($_get["intimage_x"]) ){ $intimagex = $_GET["intImage_x"]; $intimagey = $_GET["intImage_y"]; if ($intimagex > 100 && $intimagex < 200){ if ($intimagey > 25 && $intimagey < 135) echo "<p><h2>you clicked on the square</h2></p>"; if ($intimagey > 170 && $intimagey < 280) echo "<p><h2>you clicked on the circle</h2></p>"; } } else echo "<p><h2>nothing received</h2></p>?>

square/circle example Origin is here See php_imagefields.php

File Upload Form upload.html: <html> <head><title>php File Upload Form</title></head> <body> <form enctype="multipart/form-data action="upload.php method="post"> <input type="hidden" name="max_file_size value="1000000"> File:<input type="file" name="userfile"><br> <input type="submit" value="upload"> </form> </body> </html>

Character Encoding of Form-Data <form enctype= value > The enctype attribute specifies how form-data should be encoded before sending it to the server. By default, form-data is encoded to "application/x-www-form-urlencoded. This means that all characters are encoded before they are sent to the server Spaces are converted to "+" symbols Special characters are converted to ASCII HEX values).

Character Encoding <form enctype= value > Value Description application/x-www-formurlencoded sent (default setting) All characters are encoded before multipart/form-data No characters are encoded. This value is required when you are using forms that have a file upload control text/plain Spaces are converted to "+" symbols Special characters are not encoded

File Upload Form Label is automatically assigned

Receiving files $_FILES['userfile']['tmp_name'] name of the temporary copy of the file stored on the server. $_FILES['userfile']['name'] name of uploaded file. $_FILES['userfile']['size'] size of the uploaded file (in bytes). $_FILES['userfile']['type'] MIME type of the file such as image/gif. $_FILES['userfile']['error'] error that may have been generated as a result of the upload.

Upload error check $userfile_error = $_FILES['userfile']['error']; if ($userfile_error > 0) { echo 'Problem: '; switch ($userfile_error){ case 1: echo 'File exceeded upload_max_filesize'; break; case 2: echo 'File exceeded max_file_size'; break; case 3: echo 'File only partially uploaded'; break; case 4: echo 'No file uploaded'; break; } exit; } PHP.ini : upload_max_filesize = 2M HTML form : MAX_FILE_SIZE directive.

bool is_uploaded_file ( string $filename ) Returns TRUE if the file named by filename was uploaded via HTTP POST. This is useful to help ensure that a malicious user hasn't tried to trick the script into working on files upon which it should not be working --for instance, /etc/passwd.

bool move_uploaded_file ( string $filename, string $destination ) This function checks to ensure that the file designated by filename is a valid upload file (meaning that it was uploaded via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename given by destination.

Move the uploaded file $tempfile $userfile = $_FILES['userfile']['tmp_name']; = $_FILES['userfile']['name']; // Destination file on server $destfile = '/var/www/html/a /temp'. $userfile; // Do we have an uploaded file? if (is_uploaded_file($tempfile)) { // Try and move uploaded file to local directory on server if (!move_uploaded_file($tempfile, $destfile)) { echo 'Problem: Could not move to destination directory'; exit; } } else { echo 'Possible file upload attack. Filename: '. $userfile; exit; } echo 'File uploaded successfully<br /><br />'; Note: The target folder must exist for this example to work! See Upload.html, upload.php

Direct header manipulation As well as displayed hypertext, PHP can be used to add http headers in the server-client response string. header(text); Particularly useful for specifying MIME extensions Must be executed first before any content is sent!

Image Creation with PHP <?php header("content-type: image/png");//example of header $image = imagecreate(280, 180) or die("failed to create"); $bgcolour = ImageColorAllocate($image, 100, 200, 255); $fgcolour = ImageColorAllocate($image, 255, 0, 255); ImageString($image, 10, 60, 50, "Hello there!", $fgcolour); ImagePng($image); Imagedestroy($image);?> bool imagestring ( resource $image, int $font, int $x, int $y, string $string, int $color ) Note: You need to enable the loading of the gd2 extension module through php.ini

Windows: true type fonts array imagettftext ( resource $image, float $size, float $angle, int $x, int $y, int $color, string $font file, string $text ) <?php header("content-type: image/png"); $image = imagecreate(580, 280) or die("failed to create"); $bgcolour = ImageColorAllocate($image, 80, 200, 255); $fgcolour = ImageColorAllocate($image, 255, 255, 100);?> ImageString($image, 10, 60, 50, "Hello there!", $fgcolour); ImageTTFText($image, 40, 0, 30, 160, $fgcolour, Fonts/SCRIPTBL.TTF","Testing Script True Type Font"); ImagePng($image); Imagedestroy($image); Directory (relative to where the php scripts are) where Font files reside

Output on screen Results into an image that could be saved.

You can find *.ttf fonts in Linux: #find /usr -name '*.ttf' e.g., in it026945: <?php header("content-type: image/png"); $image = imagecreate(580, 280) or die("failed to create"); $bgcolour = ImageColorAllocate($image, 80, 200, 255); $fgcolour = ImageColorAllocate($image, 255, 255, 100); ImageString($image, 10, 60, 50, "Hello there!", $fgcolour); ImageTTFText($image, 40, 0, 30, 160, $fgcolour, "/usr/x11r6/lib/x11/fonts/ttf/luxirr.ttf","testing luxirr"); ImageTTFText($image, 40, 0, 30, 250, $fgcolour, "/usr/java/jdk1.5.0_01/jre/lib/oblique-fonts/lucidasansoblique.ttf", "testing LucidaSans"); ImagePng($image);?> In Linux:

PHP redirection Use header() to tell client to load another URL, e.g. <?php $url = http://www.nzherald.co.nz ; header( Location: + $url);?>

Prevent page caching: <?php // Date in the past header("expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("cache-control: no-cache"); header("pragma: no-cache");?> <html> <body>...... Note: There are options that users may set to change the browser's default caching settings. By sending the headers above, you should override any of those settings and force the browser not to cache!

Screen scrapers Taking information from other web sites. Open URLs in the same way you open local files $fp = fopen([url], r ); $webpage = file_get_contents( http://www.example.com );

Reads entire file into a string string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen = -1 ]]]] ) Searching within the include_path <?php // <= PHP 5 $file = file_get_contents('./people.txt', true); // > PHP 5 $file = file_get_contents('./people.txt', FILE_USE_INCLUDE_PATH);?> <?php // Read 14 characters starting from the 21st character $section = file_get_contents('./people.txt', NULL, NULL, 20, 14); var_dump($section);?>

Reminder on how email works Email messages are delivered across the Internet using the SMTP protocol Simple Mail Transfer Protocol Comes under the application level in the Internet protocol stack Works similar to HTTP where email transactions involve the exchange of request/response strings

Sending email Involves a three way interaction between sender, recipient, and email client Email client sends request strings to smtp server and gets back response strings

Sample email sending session 1. Client establishes connection to SMTP server Server sends 220 level response string 2. Client sends HELO request string identifying itself Server sends back 250 OK 3. Client sends mail from: request specifying address of sender Server sends back 250 sender OK 4. Client sends rcpt to: request to tell server who to send the email to Server responds with 250 rcpt ok 5. Client specifies body of email message between DATA and. Lines Server responds with 250 accepted for delivery 6. Server then queues the message for delivery A similar sequence of transactions is then carried between the SMTP server and recipient

Sample smtp interaction Sample email sending session S: 220 hamburger.edu C: HELO crepes.fr S: 250 Hello crepes.fr, pleased to meet you C: MAIL FROM: <alice@crepes.fr> S: 250 alice@crepes.fr... Sender ok C: RCPT TO: <bob@hamburger.edu> S: 250 bob@hamburger.edu... Recipient ok C: DATA S: 354 Enter mail, end with "." on a line by itself C: Do you like ketchup? C: How about pickles? C:. S: 250 Message accepted for delivery C: QUIT S: 221 hamburger.edu closing connection

Sending e-mail with PHP mail(to, subject, message, headers) You may need to specify the location of your mail server in php.ini [mail function] SMTP = smtp.hotmail.com sendmail_from = me@hotmail.com

<html> <head> <title>invitation</title> <body> <h1> Are you going to the party? </h1> <form method="post" action="response.php"> <p> <select name="attend"> <option selected value="y"> Yes, count me in! </option> <option value="n"> Sorry, can't be bothered </option> </select> </p> <p><input name="comment" type=text value="*type comments in here*" /></p> <p><input type="submit" value="submit"></p> </form> </body></html>

mail(to,subject,message,headers,parameters) Parameter to subject message headers parameters Description Required. Specifies the receiver / receivers of the email Required. Specifies the subject of the email. Note: This parameter cannot contain any newline characters Required. Defines the message to be sent. Each line should be separated with a LF (\n). Lines should not exceed 70 characters Optional. Specifies additional headers, like From, Cc, and Bcc. The additional headers should be separated with a CRLF (\r\n) Optional. Specifies an additional parameter to the sendmail program

response.php <?php $mailto = "a @localhost"; $subject = "Party RSVP"; $message = ""; $comment = $_POST['comment']; if ($comment == "*type comments in here*") { $comment = "I have no comment"; } $willgo = $_POST['attend']; if ($willgo == "Y") { $message.= "Yes I am going\n"; } elseif ($willgo == "N") { $message.= "No!\n"; } $message.= "$comment\n"; if (mail($mailto, $subject, $message)) { print "<h3>mail was sent successfully</h3><br/>"; } else { print "<h3>could not send mail</h3><br/>"; }?>

Optional headers $headers = From: my@domain.com. "\r\n"; $headers.= Cc: you@yourdomain.com. "\r\n"; $headers.= Bcc: her@herdomain.com ; mail($mailto, $subject, $message, $headers);

Extending SMTP SMTP is just a text sending/receiving protocol (like HTTP) To send other types of data (e.g. graphics attachments), we need an additional protocol Multipurpose Internet Mail Extensions MIME is an addition to the standard protocols that just sends simple text messages

Content type The key feature of MIME is the content-type identifier Each data segment in a complex email is preceded by a number of content specification headers: Content-Type: image/jpeg; name= goofy.jpg Content-Transfer-Encoding: 7bit Of course, the client needs to understands these terms

PHP and MIME PHP itself does not have support for sending emails with attachments A number of 3rd party libraries have been developed for this See the PEAR repository at: http://pear.php.net

References Php on-line documentation: http://nz.php.net/manual/en/