 2004 Tau Yenny, SI - Binus M0194 Web-based Programming Lanjut Session 1.

Slides:



Advertisements
Similar presentations
PHP Form and File Handling
Advertisements

PHP I.
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.
CGI & HTML forms CGI Common Gateway Interface  A web server is only a pipe between user-agents  and content – it does not generate content.
JavaScript Forms Form Validation Cookies CGI Programs.
HTML Form Processing Learning Web Design – Chapter 9, pp Squirrel Book – Chapter 11, pp
HTTP Hypertext Transfer Protocol. HTTP messages HTTP is the language that web clients and web servers use to talk to each other –HTTP is largely “under.
1 Active Server Pages Active Server Pages (ASPs) are Web pages ASP = server-side scripts + HTML The appearance of an Active Server Page depends on who.
Basic Scripting in VBScript  VBScript must enclosed by  No HTML code is allowed inside a VBScript code block  Nested scripting block is not allowed.
1 The World Wide Web. 2  Web Fundamentals  Pages are defined by the Hypertext Markup Language (HTML) and contain text, graphics, audio, video and software.
Nikolay Kostov Telerik Corporation
CGI Programming: Part 1. What is CGI? CGI = Common Gateway Interface Provides a standardized way for web browsers to: –Call programs on a server. –Pass.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
CST JavaScript Validating Form Data with JavaScript.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Beginning Active Server Pages Barry Sosinsky Valda Hilley Programming.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
Web forms in PHP Forms Recap  Way of allowing user interaction  Allows users to input data that can then be processed by a program / stored in a back-end.
Chapter 4 Handling User Input PHP Programming with MySQL 2nd Edition
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
FALL 2005CSI 4118 – UNIVERSITY OF OTTAWA1 Part 4 Web technologies: HTTP, CGI, PHP,Java applets)
Tips, Trick and Techniques for ASP Developers Atlanta ASP User Group Don Draper Draper Consulting, Inc.
Open Source Server Side Scripting ECA 236 Open Source Server Side Scripting Cookies & Sessions.
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.
Tutorial 14 Working with Forms and Regular Expressions.
Comp2513 Forms and CGI Server Applications Daniel L. Silver, Ph.D.
CSC 2720 Building Web Applications Cookies, URL-Rewriting, Hidden Fields and Session Management.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
IT533 Lectures Session Management in ASP.NET. Session Tracking 2 Personalization Personalization makes it possible for e-businesses to communicate effectively.
CSC 2720 Building Web Applications Getting and Setting HTTP Headers (With PHP Examples)
JavaScript, Fourth Edition Chapter 12 Updating Web Pages with AJAX.
JavaScript, Fourth Edition
9 Chapter Nine Compiled Web Server Programs. 9 Chapter Objectives Learn about Common Gateway Interface (CGI) Create CGI programs that generate dynamic.
Chapter 8 Cookies And Security JavaScript, Third Edition.
ASP.NET Programming with C# and SQL Server First Edition Chapter 3 Using Functions, Methods, and Control Structures.
CIS 451: ASP.NET Objects Dr. Ralph D. Westfall January, 2009.
Web Form Fundamentals Chapter-2 Unit-2.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
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.
PHP2. PHP Form Handling The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input. Name: Age:
Christopher M. Pascucci Basic Structural Concepts of.NET Managing State & Scope.
CSC 2720 Building Web Applications Server-side Scripting with PHP.
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.
ASP.NET Dynamic Styles Response and Request Objects.
ASP.Net, Web Forms and Web Controls 1 Outline Session Tracking Cookies Session Tracking with HttpSessionState.
ASP. What is ASP? ASP stands for Active Server Pages ASP is a Microsoft Technology ASP is a program that runs inside IIS IIS stands for Internet Information.
Operating Systems Lesson 12. HTTP vs HTML HTML: hypertext markup language ◦ Definitions of tags that are added to Web documents to control their appearance.
ASP Objects Active Server Pages (cont..) 1. 2 ASP : Objects ASP provides built-in objects for performing useful tasks that simplify web development.
 Previous lessons have focused on client-side scripts  Programs embedded in the page’s HTML code  Can also execute scripts on the server  Server-side.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ASP.NET P AGE O BJECTS.  Each ASP.NET page inherits the PAGE object  The PAGE supplies 3 built in objects:  REQUEST: All information passed to the.
ASP-2-1 SERVER AND CLIENT SIDE SCRITPING Colorado Technical University IT420 Tim Peterson.
Overview of Servlets and JSP
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.
Web Page Designing With Dreamweaver MX\Session 1\1 of 9 Session 3 PHP Advanced.
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.
1 Chapter 22 World Wide Web (HTTP) Chapter 22 World Wide Web (HTTP) Mi-Jung Choi Dept. of Computer Science and Engineering
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Chapter 5 Validating Form Data with JavaScript
HTTP – An overview.
ASP Explained By: Sarbjit Kaur.
IS333D: MULTI-TIER APPLICATION DEVELOPMENT
The Request & Response object
ASP.
Client side & Server side scripting
Browser and Server Models
Chapter 2 Interacting with the Customer
Kevin Harville Source: Webmaster in a Nutshell, O'Rielly Books
Presentation transcript:

 2004 Tau Yenny, SI - Binus M0194 Web-based Programming Lanjut Session 1

 2004 Tau Yenny, SI - Binus 2 Active Server Pages (ASP) ASP Object Model Request Object Response Object Form and QueryString ServerVariable Collection

 2004 Tau Yenny, SI - Binus 3 ASP Object Model

 2004 Tau Yenny, SI - Binus 4 ASP Objects Request Object Makes available to our script all the information that the client provides when requesting a page or submitting a form Include : the HTTP variables that identify the browser and the user the cookies that they have stored on their browser for this domain any values appended to the URL, either as a query string or in HTML controls in a section of the page

 2004 Tau Yenny, SI - Binus 5 ASP Objects Response Object to access the response that we are creating to send back to the client. It makes available : - to our script the HTTP variables that identify our server and its capabilities - information about the content we’re sending to the browser - any new cookies that will be stored on their browser for this domain Provides a series of method that we can use to create output

 2004 Tau Yenny, SI - Binus 6 ASP Objects Application Object Created when the ASP DLL is loaded in response to the first request for an ASP page. Provides a repository for storing variables and object references that are available to all the pages, which any visitor can open.

 2004 Tau Yenny, SI - Binus 7 ASP Objects Session Object Created for each visitor when they first request an ASP page from the Web site or Web application, and it remains available until the default timeout period expires. Provides a repository for storing variables and object references that are available only to the pages that visitor opens during the lifetime of the session

 2004 Tau Yenny, SI - Binus 8 ASP Objects Server Object Provides us with a series of methods and properties that are useful in scripting with ASP ASPError Object Provides a range of detailed information about the last error that occurred in ASP.

 2004 Tau Yenny, SI - Binus 9 The ASP Request Object The Request Object’s Collections Collection NameDescription ClientCertificateA collection of the values of all the fields or entries in the client certificate that the user presented to our server when accessing a page or resource. Each member is read-only. CookiesA collection of the values of all the cookies sent from the user’s system along with their request. Only cookies valid for the domain containing the resource are sent to the server. Each member is read- only. FormA collection of the values of all the HTML control elements in the section that was submitted as the request, where the value of the METHOD attribute is POST. Each member is read-only. QueryStringA collection of all the name/value pairs appended to the URL in the user’s request, or the values of all the HTML control elements in the section that was submitted as the request where the value of the METHOD attribute is GET or the attribute is omitted. Each member is read-only.

 2004 Tau Yenny, SI - Binus 10 The ASP Request Object Collection NameDescription ServerVariablesA collection of all the HTTP header values sent from the client with their request, plus the values of several environment variables for the Web server. Each member is read-only. PropertyDescription TotalBytesRead-only. Returns the total number of bytes in the body of the request sent by the client. The Request Object’s Property MethodDescription BinaryRead(count)Retrieve count bytes of data from the client’s request when the data is sent to the server as part of a POST request. It returns a Variant array (or SafeArray). Cannot be used successfully if the ASP code has already referenced the Request.Form collection. Likewise, the Request.Form collection cannot be successfully accessed if you have used the BinaryRead method. The Request Object’s Method

 2004 Tau Yenny, SI - Binus 11 The ASP Response Object The Response Object’s Collection Collection NameDescription CookiesA collection containing the values of all the cookies that will be sent back to the client in the current response. The collection is write only. The Response Object’s Properties PropertyDescription Buffer = True | FalseRead/write. Boolean. Specifies if the output created by an ASP page will be held in the IIS buffer until all of the server scripts in the current page have been processed or until the Flush or End method is called. It must be set before any output is sent to IIS, including HTTP header information, so it should be the first line of the.asp file after the statement. Buffering is on (True) by default in ASP 3.0, whereas it was off (False) by default in earlier versions.

 2004 Tau Yenny, SI - Binus 12 The ASP Response Object PropertyDescription CacheControl “setting”Read/write. String. Set this property to “Public” to allow proxy servers to cache the page, or “Private” to prevent proxy caching taking place. Charset = “value”Read/write. String. Appends the name of the character set (for example, ISO-LATIN-7) to the HTTP Content Type header created by the server for each response. ContentType = “MIME-type”Read/write. String. Specifies the HTTP content type for the response, as a standard MIME-type (such as “text/xml” or image/gif”). If omitted, the MIME-type “text/html” is used. The content type tells the browser what type of content to expect. Expires minutesRead/write. Number. Specifies the length of time in minutes that a page is valid for. If the user returns to the same page before it expires, the cached version is displayed. After that period, it expires, and will not be held in a private (user) or public (proxy) cache. ExpiresAbsolute #date[time]# Read/write. Date/Time. Specifies the absolute date and time when a page will expire and no longer be valid. If the user returns to the same page before it expires, the cached version displayed. After that time, it expires, and should not be held in a private (user) or public (proxy) cache.

 2004 Tau Yenny, SI - Binus 13 The ASP Response Object PropertyDescription IsClientConnectedRead-only. Boolean. Return an indication of whether the client is still connected to and loading the page from the server. Can be used to end processing (with the Response.End method) if a client moves to another page before the current one has finished executing. PICS (“PICS-label-string”)Write only. String. Creates a PICS headers define the content of the page in terms of violence, sex, bad language, etc. Status = ”code message”Read/Write. String. Specifies the status value and message that will be sent to the client in the HTTP headers of the response to indicate an error or successful processing of the page. Example are “200 OK” and “404 Not Found”.

 2004 Tau Yenny, SI - Binus 14 The ASP Response Object The Response Object’s Methods MethodDescription AddHeader (“name”, “content”) Creates a custom HTTP header using the name and content values and adds it to the response. Will not replace an existing header of the same name. Once a header has been added, it cannot be removed. Must be used before any page content (i.e. text and HTML) is sent to the client. AppendToLog (“string”)Adds a string to the end of the Web server log entry for this request when W3C Extended Log File Format is in use. Requires at least the URI Stem value to be selected in the Extended Properties page for the site containing the page. BinaryWrite (SafeArray)Writes the content of a Variant-type SafeArray to the current HTTP output stream without any character conversion. Useful for writing non-string information, such as binary data required by a custom application or the bytes to make up an image file. Clear ( )Erases any existing buffered page content from the IIS response buffer when Response.Buffer is True. Does not erase HTTP response headers. Can be used to abort a partly completed page.

 2004 Tau Yenny, SI - Binus 15 The ASP Response Object MethodDescription End ( )Stops ASP from processing the page script and returns the currently created content, then aborts any further processing of this page. Flush ( )Sends all currently buffered page content in the IIS buffer to the client when Response.Buffer is True. Can be used to send parts of a long page to the client individually. Redirect (“url”)Instructs the browser to load the page in the string url parameter by sending a “302 Object Moved” HTTP header in the response. Write (“string”)Writes the specified string to the current HTTP response stream and IIS buffer, so that it becomes part of the returned page.

 2004 Tau Yenny, SI - Binus 16 Working with Form and QueryString Collection ASP collection are an array of values, can be accessed using a text string key (not case sensitive) or an integer index. For example, in default.html : FirstName : 5.LastName :

 2004 Tau Yenny, SI - Binus 17 Working with Form and QueryString Collection We can access the values by accessing the ASP Form Collection We can also use the integer index of the control on the form. The range of indexes starts at 1 for the 1 st control defined in the HTML. This technique is not recommended <% 4.strFirstName = Request.Form ("FirstName") 5.strLastName = Request.Form ("LastName") 6.Response.Write "Using text string key: " 7.Response.Write strFirstName & " " & strLastName & " " 8.strFirstName2 = Request.Form(1) 9.strLastName2 = Request.Form(2) 10.Response.Write " Using index : " 11.Response.Write strFirstName2 & " " & strLastName2 12.%> show_request.asp

 2004 Tau Yenny, SI - Binus 18 Working with Form and QueryString Collection

 2004 Tau Yenny, SI - Binus 19 Working with Form and QueryString Collection It’s also possible to collect the entire set of values from the form into a single string variable by just referencing the collection, and without providing a key or index. strAllFormContent = Request.Form If our text boxes contain the values Yos and Stefan Hideki, the Request.Form statement will return the string: FirstName=Yos&LastName=Stefan+Hideki The values are provided in name/value pairs. Each name/value pair is separated from the others with an ampersand (&) character <% 4.strAllFormContent = Request.Form 5.Response.Write strAllFormContent 6.%> 7. 8.

 2004 Tau Yenny, SI - Binus 20 Working with Form and QueryString Collection

 2004 Tau Yenny, SI - Binus 21 Iterating Through an ASP Collection There are 2 ways to iterate through all the members of an ASP collection. We can using an For and integer index For intLoop = 1 to Request.Form.Count Response.Write Request.Form(intLoop) & “ ” Next A better method is use the For Each.. Next construct For Each objItem In Request.Form Response.Write objItem & “ = “ & Request.Form(objItem) & “ ” Next

 2004 Tau Yenny, SI - Binus 22 Iterating Through an ASP Collection <% 4.Response.Write "Using counter : " 5.For intLoop = 1 to Request.Form.Count 6.Response.Write Request.Form(intLoop) & " " 7.Next 8.Response.Write " Using For Each : " 9.For Each objItem In Request.Form 10. Response.Write objItem & " = " & Request.Form(objItem) & " " 11.Next 12.%> show_request.asp

 2004 Tau Yenny, SI - Binus 23 Iterating Through an ASP Collection

 2004 Tau Yenny, SI - Binus 24 Multiple Value Collection Members In some cases, an individual member of an ASP collection may be made up of more than one value. This occurs when several controls have the same NAME attribute defined in the HTML, for example: default.html show_request.asp <% 4. Response.Write Request.Form("OtherHobby") 5. %> 6. 7.

 2004 Tau Yenny, SI - Binus 25 Multiple Value Collection Members

 2004 Tau Yenny, SI - Binus 26 Multiple Value Collection Members To be access individual values, we can use the rather convoluted code : <% 4. For Each objItem In Request.Form 5.If Request.Form(objItem).Count > 1 Then 'If More than 1 value 6. Response.Write objItem & " : " 7. For intLoop = 1 to Request.Form(objItem).Count 8.Response.Write "Subkey " & intLoop & " value = " _ 9.& Request.Form(objItem)(intLoop) & " " 10. Next 11.Else 12. Response.Write objItem & " = " & Request.Form(objItem) & " " 13.End If 14. Next 15.%>

 2004 Tau Yenny, SI - Binus 27 Multiple Value Collection Members

 2004 Tau Yenny, SI - Binus 28 Multiple Value Collection Members <% 4.Select Case Request.Form("btnSubmit") 5.Case "Next" 6.Response.Redirect "page_3.html" 7.Case "Previous" 8.Response.Redirect "page_1.html" 9.Case "Cancel" 10.Response.Redirect "default.html" 11.End Select 12.%>

 2004 Tau Yenny, SI - Binus 29 Multiple Value Collection Members

 2004 Tau Yenny, SI - Binus 30 The Difference Between Forms and QueryString Append 1 or more name/value pair to the URL of the page we’re requesting, they become the query string for the request, and are exposed to our ASP page in the QueryString collection. Therefore, the only way to send values to ASP from any of these actions is through the QueryString collection, by appending them to the URL The URL/query String combination cannot contain any spaces or other illegal characters. Illegal characters are those that are used to delimit parts of the URL and query string, for example ‘/’, ‘:’, ‘?’, and ‘&’. Spaces must be convert to ‘+’ format. ASP Server object provides URLEncode method for handling this conversion. The values appear in the Request.QueryString, and are accessed, in the same way as the FORM collection examples. The URL and query string combination :

 2004 Tau Yenny, SI - Binus 31 QueryString <% 4.strFirstName = Request.QueryString ("FirstName") 5.strLastName = Request.QueryString ("LastName") 6.strAll = Request.QueryString 7.Response.Write "Using query string: " 8.Response.Write strFirstName & " " & strLastName & " " 9.Response.Write strAll 10.%> URL and query string

 2004 Tau Yenny, SI - Binus 32 The GET and POST Methods of a FORM There are 2 common method for requesting a page or resource from a Web server over HTTP.  GET To get the resource directly. Get is the default method.  POST To post values to a resource.

 2004 Tau Yenny, SI - Binus 33 The GET and POST Methods of a FORM Use “GET” or omit the attribute, the browser bundles up the values in all the controls on the form into a query string, and appends it to the URL of the page being requested. The request is exposed through the ASP Request.QueryString collection. Use “POST”, the browser wraps the values up within the HTTP headers it sends to the server, and they are exposed to ASP via the Request.Form collection.

 2004 Tau Yenny, SI - Binus 34 ServerVariables Collection Contains a combination of values that represent the HTTP headers sent from the client Self-Referencing Pages Detail of our Web server and path information of the current page. " METHOD="POST"> The same effect is obtained with the HTTP “SCRIPT_NAME” value : " METHOD="POST">

 2004 Tau Yenny, SI - Binus 35 Self-Referencing Pages " METHOD="POST"> 4. 5.<% 6.strFullPath = Request.ServerVariables ("PATH_INFO") 7.strPathOnly = Left(strFullPath, InStrRev(strFullPath, "/")) 8.strNextPage = strPathOnly & "page_3.html" 9.Response.Write "Full Path : " & strFullPath & " " 10.Response.Write "Path Only : " & strPathOnly & " " 11.Response.Write "Next Page : " & strNextPage & " " 12.%> 13. "> Next Page

 2004 Tau Yenny, SI - Binus 36 Self-Referencing Pages

 2004 Tau Yenny, SI - Binus 37 ServerVariables Collection Detecting the Browser Version Another useful value is the user agent string for our visitor’s browser. In the Detecting Browser Type page (browsertype.asp), we are using the “HTTP_USER_AGENT” value from the ServerVariables collection to retrieve the user agent string, and some script to parse this and look for a manufacturer name and browser version.

 2004 Tau Yenny, SI - Binus 38 Detecting the Browser Version Detecting the Browser Type <% 7. strUA = Request.ServerVariables("HTTP_USER_AGENT") 8. Response.Write "The User Agent string is " & strUA & " " 9. If InStr(StrUA, "MSIE") Then 10. Response.Write "To upgrade your browser go to " _ 11. & "<A HREF=" & chr(34) & " _ 12. & chr(34) & "> " 13. intVersion = CInt(Mid(strUA, InStr(StrUA,"MSIE") + 5, 1)) 14. If intVersion >=4 then 15. Response.Write "You can use Microsoft Dynamic HTML" 16. End If 17. End If 18. %>

 2004 Tau Yenny, SI - Binus 39 Detecting the Browser Version

 2004 Tau Yenny, SI - Binus 40 ServerVariables Collection Detecting the Browser Language “HTTP_ACCEPT_LANGUAGE” contains a language code, which was selected when the browser was installed or is hard-coded into the user’s locale-specific version. Example of language code are en-us (English, United States), de-at (German, Austrian) and es-pe (Spanish, Peru). A language code can also be generic and omit the dialect identifier. We can detect the language code and load an appropriate locale-specific, language-specific or geographically-specific version of our pages automatically.

 2004 Tau Yenny, SI - Binus Detecting the Browser Language <% 7.strLocale = LCase(Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")) 8.Response.Write "The Browser Language code is " & strLocale & " - " 9.Select Case strLocale 10.Case "en-gb" : Response.Write "English, United Kingdom" 11.Case "en-us" : Response.Write "English, United States" 12.Case "es-pe" : Response.Write "Spanish, Peru" 13.Case "id" : Response.Write "Indonesian" 14.case Else : Response.Write "Another Language" 15.End Select 16.Response.Write " " 17.%>

 2004 Tau Yenny, SI - Binus 42 ServerVariables Collection Other Useful ServerVariables Values  Check if the visitor accessed our site through the default port 80 or a different one. We can query the user name if we force our users to log on and be authenticated by our server.  “AUTH_USER” Return the authenticated user string.  “SERVER_NAME” Return the server name string.

 2004 Tau Yenny, SI - Binus Detecting the Browser <% 7.Response.Write "PORT : " & Request.ServerVariables("SERVER_PORT") & " " 8.If Request.ServerVariables("SERVER_PORT") = "80" Then 9.Response.Write "Default PORT" 10.Else 11.Response.Write "Another PORT" 12.End If 13.%>