School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

24-Aug-14 HTML Forms. 2 What are forms? is just another kind of HTML tag HTML forms are used to create (rather primitive) GUIs on Web pages Usually the.
UFCE8V-20-3 Information Systems Development 3 (SHAPE HK)
Cookies, Sessions. Server Side Includes You can insert the content of one file into another file before the server executes it, with the require() function.
JavaScript Forms Form Validation Cookies. What JavaScript can do  Control document appearance and content  Control the browser  Interact with user.
JavaScript Forms Form Validation Cookies CGI Programs.
PHP Scripts HTML Forms Two-tier Software Architecture PHP Tools.
Christopher M. Pascucci Basic Structural Concepts of.NET Browser – Server Interaction.
Forms, Validation Week 7 INFM 603. Announcements Try placing today’s example in htdocs (XAMPP). This will allow you to execute examples that rely on PHP.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
1 Web Developer & Design Foundations with XHTML Chapter 6 Key Concepts.
Lecture 3 – Data Storage with XML+AJAX and MySQL+socket.io
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
INTERNET APPLICATION DEVELOPMENT For More visit:
CHAPTER 12 COOKIES AND SESSIONS. INTRO HTTP is a stateless technology Each page rendered by a browser is unrelated to other pages – even if they are from.
1 Forms A form is the usual way that information is gotten from a browser to a server –HTML has tags to create a collection of objects that implement this.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Server-side Scripting Powering the webs favourite services.
Introduction to InfoSec – Recitation 7 Nir Krakowski (nirkrako at post.tau.ac.il) Itamar Gilad (itamargi at post.tau.ac.il)
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
JavaScript, Fourth Edition
HTML - Forms By Joaquin Vila, Ph.D.. Form Tag The FORM tag specifies a fill-out form within an HTML document. More than one fill-out form can be in a.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
Week 9 PHP Cookies and Session Introduction to JavaScript.
Python CGI programming
CSC 2720 Building Web Applications HTML Forms. Introduction  HTML forms are used to collect user input.  The collected input is typically sent to a.
Chapter 8 Cookies And Security JavaScript, Third Edition.
Introduction to MySQL Lab no. 10 Advance Database Management System.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
Web Scripting [PHP] CIS166AE Wednesdays 6:00pm – 9:50pm Rob Loy.
PHP1-1 PHP Lecture 2 Xingquan (Hill) Zhu
Website Development with PHP and MySQL Saving Data.
Chapter 6 Server-side Programming: Java Servlets
1 Chapter 9 – Cookies, Sessions, FTP, and More spring into PHP 5 by Steven Holzner Slides were developed by Jack Davis College of Information Science.
1 © Netskills Quality Internet Training, University of Newcastle HTML Forms © Netskills, Quality Internet Training, University of Newcastle Netskills is.
HTML - Forms By Joaquin Vila, Ph.D.. Form Tag The FORM tag specifies a fill-out form within an HTML document. More than one fill-out form can be in a.
HTML, PHP, and MySQL: Putting It All Together. Making a Form Input tags Types: “text” “radio” “checkboxes” “submit”
XHTML & Forms. PHP and the WWW PHP and HTML forms – Forms are the main way users can interact with your PHP scrip Typical usage of the form tag in HTML.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting PHP & MySQL.
Controlling Web Site Access Using Logins CS 320. Basic Approach HTML form a php page that collects the username and password  Sends them to second PHP.
Forms Collecting Data CSS Class 5. Forms Create a form Add text box Add labels Add check boxes and radio buttons Build a drop-down list Group drop-down.
Sessions and Cookies State Management, Cookies, Sessions, Hidden Fields SoftUni Team Technical Trainers Software University
HTLM Forms CS3505. Form Handling in Browser html User Files out form WEbBROWSErWEbBROWSEr User read response submit Get URL?input html Get file html script.
Copyright © Texas Education Agency, All rights reserved.1 Web Technologies Website Forms / Data Acquisition.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Since you’ll need a place for the user to enter a search query. Every form must have these basic components: – The submission type defined with the method.
1 PHP HTTP After this lecture, you should be able to know: How to create and process web forms with HTML and PHP. How to create and process web forms with.
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.
CGS 3066: Web Programming and Design Spring 2016 PHP.
Unit 4 Working with data. Form Element HTML forms are used to pass data to a server. A form can contain input elements like text fields, checkboxes, radio-buttons,
FORMS Explained By: Jasdeep Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Programming for the Web Cookies & Sessions Dónal Mulligan BSc MA
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.
National College of Science & Information Technology.
Introduction to Dynamic Web Programming
How to Write Web Forms By Mimi Opkins.
CIIT-Human Computer Interaction-CSC456-Fall-2015-Mr
19.10 Using Cookies A cookie is a piece of information that’s stored by a server in a text file on a client’s computer to maintain information about.
Chapter 19 PHP Part III Credits: Parts of the slides are based on slides created by textbook authors, P.J. Deitel and H. M. Deitel by Prentice Hall ©
Validation and Building Small Apps
ISC440: Web Programming 2 Server-side Scripting PHP 3
<?php require("header.htm"); ?>
Software Engineering for Internet Applications
PHP-II.
Presentation transcript:

School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database

School of Computing and Information Systems CS 371 Web Application Programming Overview name SubmitCancel Internet client server clients sends name and to php script

School of Computing and Information Systems CS 371 Web Application Programming HTML Forms all forms must be surrounded by form tag controls are created using the tags: input (text, checkbox, radio, submit, image, reset, button, hidden, file) button textarea select (optgroup, option) specify php script in action attribute specify method as GET or POST

School of Computing and Information Systems CS 371 Web Application Programming Method: Post vs. Get Get data is appended to URL number of chars limited by browser user can see (and change) vars can be bookmarked Post data is sent via separate http message number of chars is unlimited cannot be bookmarked

School of Computing and Information Systems CS 371 Web Application Programming How PHP Receives Data: superglobals Get $_GET[‘nameFirst’] // value of html element with a name of ‘nameFirst’ sent using “GET” Post $_POST[‘age’] // value of html element with a name of ‘age’ sent using “POST” There are other ways but these are the most popular

School of Computing and Information Systems CS 371 Web Application Programming HTML Forms Variable Names and Values use name attribute of select and values of the options GVSU Calvin Hope MSU

School of Computing and Information Systems CS 371 Web Application Programming Using Form Data After the form is “submitted” the parameters are sent to the server which executes the PHP script The PHP script then has access to the variables using the superglobals $_GET or $_POST depending on the method Data can then be stored in a database or processed in some other way

School of Computing and Information Systems CS 371 Web Application Programming Cookies Cookies can be set and accessed on both the client (remember javascript?) and server side. Is it more important to access them through a client or server script? Can you generalize about what kind of data should be saved in cookies? What is more secure, cookies or storage on the server?

School of Computing and Information Systems CS 371 Web Application Programming Setting Cookies setcookie(name,value,expire,path,domain) expire is in seconds (60*60*24=1 day) path and domain are optional must be before the tag ex: setcookie(“id”,”123”,time()+3600);

School of Computing and Information Systems CS 371 Web Application Programming Using cookies isset(“id”) returns true if id is a cookie $_COOKIE(“id”) returns the value of the cookie “id” these can be used anywhere in document to delete a cookie use an expires less than current: setcookie(“id”,””,time()-3600)

School of Computing and Information Systems CS 371 Web Application Programming Keeping Track of Visitors web programming is essentially stateless when a script is called can it tell that the user is registered? that they completed steps 1 through n ? that this is the same customer who chose product z ? how to establish state? cookies?, clumsy hidden variables?, unwise for security

School of Computing and Information Systems CS 371 Web Application Programming Sessions Sessions are a built-in way to keep track of the activity of a user during a short period of time transparently generate and recognize session ids allow for variables that store data for the duration of the session default timeout is 24 minutes

School of Computing and Information Systems CS 371 Web Application Programming The Glue that Holds Sessions Together Use before the tag to both start and continue a session php stores the session id on the client (cookie…) when it sees the session_start(), if it can find a match on your computer it continues that session If there is no match, it creates a new session id and starts a new session

School of Computing and Information Systems CS 371 Web Application Programming Session Variables session variables are superglobals like $_GET, $_POST and $_cookie $_SESSION['userId']="1234"; if($_SESSION['shipMeth']=='UPS') … session variables are available until they are removed or the session is over - by default it lasts until user closes browser unset($_SESSION['id']); session_unset(); //removes all vars session_destroy();

School of Computing and Information Systems CS 371 Web Application Programming simple way to send mail($to,$subject,$msg,$headers); $to must be valid address $headers can be typical header data (from, etc)

School of Computing and Information Systems CS 371 Web Application Programming Long Term Storage Internet clie nt server database

School of Computing and Information Systems CS 371 Web Application Programming SQL You should refamiliarize yourself with create table alter table drop table data types in MySql select queries update and delete queries Ira should have ed you MySql password

School of Computing and Information Systems CS 371 Web Application Programming Using MySql from PHP many functions especially for mysql process is: connect to localhost switch to your database (use database) issue queries close database must encode password into connection string - why won't anyone see this?

School of Computing and Information Systems CS 371 Web Application Programming Connecting to Localhost it is possible to connect to a remote database but our EOS sites will connect to the EOS MySql server connect state- ment uses location, id and password. Important to verify that connection was made (die outputs message and terminates) $con = mysql_connect("cis.gvsu.edu","pete","abc"); if (!$con){ die('Could not connect: '.mysql_error()); }

School of Computing and Information Systems CS 371 Web Application Programming Using Database after connecting, you must set the database using mysql_select_db when finished use mysql_close $con = mysql_connect("cis.gvsu.edu","pete","abc"); if (!$con){ die('Could not connect: '.mysql_error()); } mysql_select_db("my_db", $con);... mysql_close($con);

School of Computing and Information Systems CS 371 Web Application Programming Queries mysql_query issues queries and returns result sets queries (like update and delete) that do not return results simply return true or false can use functions to find id (primary key) for inserts or affected rows for update/delete $result = mysql_query("SELECT * FROM cust"); while($row = mysql_fetch_array($result)){ echo $row['fName']. " ". $row['lName']; }

School of Computing and Information Systems CS 371 Web Application Programming php - DOM same basic concept as javaScript except don't have access to current document, so cannot modify html – so what more likely used for creating xml docs methods of a DOMDocument: $doc = new DOMDocument('1.0', 'iso '); $root = $doc->createElement('CS371'); $doc->appendChild($root);

School of Computing and Information Systems CS 371 Web Application Programming Desktop vs Web applications how do sessions allow web apps to be more like desktop apps (without direct connection)? what do forms represent? how do the different types of memory (cookies, session vars, files/db) relate to a desktop environment?

School of Computing and Information Systems CS 371 Web Application Programming REST constraints using javaScript & PHP client-server: separation of concern stateless – how does session vars fit? cacheble – responses must define themselves as cacheable or not – why? layered system – clients cannot tell if connected to end server or intermediary code on demand (javaScript) uniform interface – simplifies and decouples the architecture