Web Technologies-II PDF

Document Details

2022

Dr. A. B. Nimbalkar

Tags

web technologies computer science web programming textbook

Summary

This is a textbook on web technologies for undergraduate students. It covers web techniques, XML, Javascript, jQuery, Ajax, and PHP frameworks. Published by Nirali Prakashan in January 2022.

Full Transcript

A Book Of W EB TECHNOLOGIES – II For T.Y.B.Sc. Computer Science : Semester – VI [Course Code CS 363 : Credits – 2] CBCS Pattern As Per New Syllabus, Effective from June 2021 Dr. A. B. Nimbalkar M.C.S., M.Phil. D.C....

A Book Of W EB TECHNOLOGIES – II For T.Y.B.Sc. Computer Science : Semester – VI [Course Code CS 363 : Credits – 2] CBCS Pattern As Per New Syllabus, Effective from June 2021 Dr. A. B. Nimbalkar M.C.S., M.Phil. D.C.L, Ph.D. (Comp. Sci.) Asst. Professor, Department of Computer Science Annasaheb Magar Mahavidyalaya, Hadapsar Pune Price ` 270.00 N5948 WEB TECHNOLOGIES - II ISBN 978-93-5451-325-1 First Edition : January 2022 © : Author The text of this publication, or any part thereof, should not be reproduced or transmitted in any form or stored in any computer storage system or device for distribution including photocopy, recording, taping or information retrieval system or reproduced on any disc, tape, perforated media or other information storage device etc., without the written permission of Author with whom the rights are reserved. Breach of this condition is liable for legal action. Every effort has been made to avoid errors or omissions in this publication. In spite of this, errors may have crept in. Any mistake, error or discrepancy so noted and shall be brought to our notice shall be taken care of in the next edition. It is notified that neither the publisher nor the author or seller shall be responsible for any damage or loss of action to any one, of any kind, in any manner, therefrom. The reader must cross check all the facts and contents with original Government notification or publications. Published By : Polyplate Printed By : NIRALI PRAKASHAN YOGIRAJ PRINTERS AND BINDERS Abhyudaya Pragati, 1312, Shivaji Nagar, Survey No. 10/1A, Ghule Industrial Estate Off J.M. Road, Pune – 411005 Nanded Gaon Road Tel - (020) 25512336/37/39 Nanded, Pune - 411041 Email : [email protected] DISTRIBUTION CENTRES PUNE Nirali Prakashan Nirali Prakashan (For orders outside Pune) (For orders within Pune) S. No. 28/27, Dhayari Narhe Road, Near Asian College 119, Budhwar Peth, Jogeshwari Mandir Lane Pune 411041, Maharashtra Pune 411002, Maharashtra Tel : (020) 24690204; Mobile : 9657703143 Tel : (020) 2445 2044; Mobile : 9657703145 Email : [email protected] Email : [email protected] MUMBAI Nirali Prakashan Rasdhara Co-op. Hsg. Society Ltd., 'D' Wing Ground Floor, 385 S.V.P. Road Girgaum, Mumbai 400004, Maharashtra Mobile : 7045821020, Tel : (022) 2385 6339 / 2386 9976 Email : [email protected] DISTRIBUTION BRANCHES DELHI BENGALURU NAGPUR Nirali Prakashan Nirali Prakashan Nirali Prakashan Room No. 2 Ground Floor Maitri Ground Floor, Jaya Apartments, Above Maratha Mandir, Shop No. 3, 4575/15 Omkar Tower, Agarwal Road No. 99, 6th Cross, 6th Main, First Floor, Rani Jhanshi Square, Darya Ganj, New Delhi 110002 Malleswaram, Bengaluru 560003 Sitabuldi Nagpur 440012 (MAH) Mobile : 9555778814/9818561840 Karnataka; Mob : 9686821074 Tel : (0712) 254 7129 Email : [email protected] Email : [email protected] Email : [email protected] KOLHAPUR JALGAON SOLAPUR Nirali Prakashan Nirali Prakashan Nirali Prakashan 438/2, Bhosale Plaza, Ground Floor 34, V. V. Golani Market, Navi Peth, R-158/2, Avanti Nagar, Near Golden Khasbag, Opp. Balgopal Talim Jalgaon 425001, Maharashtra Gate, Pune Naka Chowk Kolhapur 416 012, Maharashtra Tel : (0257) 222 0395 Solapur 413001, Maharashtra Mob : 9850046155 Mob : 94234 91860 Mobile 9890918687 Email : [email protected] Email : [email protected] Email : [email protected] [email protected] | www.pragationline.com Also find us on www.facebook.com/niralibooks Preface … I take an opportunity to present this Text Book on "Web Technologies - II" to the students of Third Year B.Sc. (Computer Science) Semester-VI as per the New Syllabus, June 2021. The book has its own unique features. It brings out the subject in a very simple and lucid manner for easy and comprehensive understanding of the basic concepts. The book covers theory of Introduction to Web Techniques, XML, JavaScript and jQuery, Ajax, and PHP Framework CodeIgniter. A special word of thank to Shri. Dineshbhai Furia, and Mr. Jignesh Furia for showing full faith in me to write this text book. I also thank to Mr. Amar Salunkhe and Mr. Akbar Shaikh of M/s Nirali Prakashan for their excellent co-operation. I also thank Ms. Chaitali Takle, Mr. Ravindra Walodare, Mr. Sachin Shinde, Mr. Ashok Bodke, Mr. Moshin Sayyed and Mr. Nitin Thorat. Although every care has been taken to check mistakes and misprints, any errors, omission and suggestions from teachers and students for the improvement of this text book shall be most welcome. Author Syllabus … 1. Introduction to Web Techniques (6 Lectures) Variables Server Information Processing Forms Setting Response Headers Maintaining State PHP Error Handling 2. XML (6 Lectures) What is XML? XML Document Structure PHP and XML XML Parser The Document Object Model The Simple XML Extension Changing a Value with SimpleXML 3. JavaScript and jQuery (10 Lectures) Overview of JavaScript Object Orientation and JavaScript Basic Syntax (JS Datatypes, JS Variables ) Primitives, Operations and Expressions Screen Output and Keyboard Input (Verification and Validation) JS Control Statements and JS Functions JavaScript HTML DOM Events (onmouseup, onmousedown, onclick, onload, onmouseover, onmouseout) JS Popup Boxes (Alert, Confirm, Prompt) Jquery Library, Including Jquery Library in Page Jquery Selector, DOM Manipulation using jQuery 4. AJAX (6 Lectures) Introduction of AJAX AJAX Web Application Model AJAX - PHP Framework Performing AJAX Validation Handling XML Data using PHP and AJAX Connecting Database using PHP and AJAX 5. PHP Framework CodeIgniter (8 Lectures) CodeIgniter - Overview, Installing CodeIgniter Application Architecture MVC Framework, Basic Concept of CodeIgniter, Libraries Working with Databases Load External JS and CSS Page and Redirecting from Controller, Adding JS and CSS, Page Redirection Loading Dynamic Data on Page and Session Management, Cookies Management Contents … 1. Introduction to Web Techniques 1.1 – 1.58 2. XML 2.1 – 2.42 3. JavaScript and jQuery 3.1 – 3.96 4. AJAX 4.1 – 4.30 5. PHP Framework CodeIgniter 5.1 – 5.40 CHAPTER 1 Introduction to Web Techniques Objectives… To understand Server Variables Concepts To study Server Information To learn Forms and Processing of Form To Setting Response Headers and Maintaining State To understand Error Handling in PHP 1.0 INTRODUCTION Nowadays, PHP is becoming a standard in the world of Web programming with its simplicity, performance, reliability, flexibility and speed. PHP was designed/developed as a Web scripting language and although it is possible to use it in purely command-line and GUI scripts, the Web accounts for the vast majority of PHP uses. A dynamic Web site may have forms, sessions, and sometimes redirection. This chapter explains how to implement those things in PHP. The Web runs on the HyperText Transfer Protocol (HTTP) and this protocol governs how web browsers request files from web servers and how the servers send the files back. Web technology is essential today because Internet has become the number one source to information and many of the traditional software applications have become Web Applications. 1.1 VARIABLES [Oct. 17, April 18] Every time we click a link or submit a form, we send a great deal of data about the system and the browser to the Web server and each time the web server responds, it sends us a great deal of data about itself. PHP has the capability to capture that data. For instance, if we go to a PHP driven website and log in, it’s likely that a predefined variable $_POST is filled (on server) with the username and password, another predefined variable named $_SERVER contains information about the current Web server environment. 1.1 Web Technologies - II Introduction to Web Techniques PHP automatically have some variables called predefined variables available anywhere in the program. They are array variables. These variables are: $_ENV, $_GET, $_POST, $_COOKIE, and $_SERVER, referred to as EGPCS. There is a setting in the configuration file (php.ini) called register_globals. The default value is off and it restricts how we can access some predefined variables. The register_globals determine whether or not to register the EGPCS variables as global variables. Regardless of the setting of the option register_globals, PHP creates six global arrays that contain the EGPCS information as given below: 1. $_COOKIE: This global array contains any cookie values passed as part of the request, where the keys of the array are the names of the cookies. 2. $_GET: This global array contains any parameters that are part of a GET request, where the keys of the array are the names of the form parameters. 3. $_POST: This global array contains any parameters that are part of a POST request, where the keys of the array are the names of the form parameters. 4. $_FILES: This global array contains information about any uploaded files. [Oct. 17, April 18] 5. $_SERVER: This global array contains useful information about the web server, as described in the next section. [April 19] 6. $_ENV: This global array contains the values of any environment variables, where the keys of the array are the names of the environment variables. Above variables are not only global, but also visible from within function definitions, unlike their longer counterparts. The $_REQUEST array is also created by PHP if the register_globals option is on. The $_REQUEST array contains the elements of the $_GET, $_POST, and $_COOKIE arrays. PHP also creates a variable called $PHP_SELF, which holds the name of the current script, relative to the document root. Several predefined variables in PHP are "superglobals", which means that they are always accessible, regardless of scope and we can access them from any function, class or file without having to do anything special. The PHP superglobal variables are $GLOBALS, $_SERVER, $_REQUEST, $_POST, $_GET, $_FILES, $_ENV, $_COOKIE, and $_SESSION. 1.2 Web Technologies - II Introduction to Web Techniques 1.2 SERVER INFORMATION [April 18] The $_SERVER is an associative array contains a lot of information from the Web server. The following table lists the most important elements that can go inside $_SERVER: Sr. Element/Code Description No. 1. $_SERVER['PHP_SELF'] Returns the filename of the currently executing script. 2. $_SERVER['GATEWAY_INTERFACE'] Returns the version of the Common Gateway Interface (CGI) the server is using. 3. $_SERVER['SERVER_ADDR'] Returns the IP address of the host server. 4. $_SERVER['SERVER_NAME'] Returns the name of the host server (such as www.nirali.com). 5. $_SERVER['SERVER_SOFTWARE'] Returns the server identification string (such as Apache/2.2.24). 6. $_SERVER['SERVER_PROTOCOL'] Returns the name and revision of the information protocol (such as HTTP/1.1). 7. $_SERVER['REQUEST_METHOD'] Returns the request method used to access the page (such as POST). 8. $_SERVER['REQUEST_TIME'] Returns the timestamp of the start of the request (such as 1377687496). 9. $_SERVER['QUERY_STRING'] Returns the query string if the page is accessed via a query string. 10. $_SERVER['HTTP_ACCEPT'] Returns the Accept header from the current request. 11. $_SERVER['HTTP_ACCEPT_CHARSET'] Returns the Accept_Charset header from the current request (such as utf-8,ISO-8859-1). 12. $_SERVER['HTTP_HOST'] Returns the Host header from the current request. 13. $_SERVER['HTTP_REFERER'] Returns the complete URL of the current page (not reliable because not all user-agents support it). 14. $_SERVER['HTTPS'] Is the script queried through a secure HTTP protocol. contd. … 1.3 Web Technologies - II Introduction to Web Techniques 15. $_SERVER['REMOTE_ADDR'] Returns the IP address from where the user is viewing the current page. 16. $_SERVER['REMOTE_HOST'] Returns the Host name from where the user is viewing the current page. 17. $_SERVER['REMOTE_PORT'] Returns the port being used on the user's machine to communicate with the web server. 18. $_SERVER['SCRIPT_FILENAME'] Returns the absolute pathname of the currently executing script. 19. $_SERVER['SERVER_ADMIN'] Returns the value given to the SERVER_ADMIN directive in the web server configuration file (if your script runs on a virtual host, it will be the value defined for that virtual host) (such as [email protected]). 20. $_SERVER['SERVER_PORT'] Returns the port on the server machine being used by the web server for communication (such as 80). 21. $_SERVER['SERVER_SIGNATURE'] Returns the server version and virtual host name which are added to server-generated pages. 22. $_SERVER['PATH_TRANSLATED'] Returns the file system based path to the current script. 23. $_SERVER['SCRIPT_NAME'] Returns the path of the current script. 24. $_SERVER['SCRIPT_URI'] Returns the URI of the current page. 1.3 PROCESSING FORMS Forms are essential parts in web development. Forms are used to communicate between users and the server. Form is a way to get information of the user to the server and let the server do something in response to the user’s input. We use form to register in a website, to login, to send feedback, to place order online, to book ticket online etc. After submitting the form, the form is processed by PHP on the server. In PHP the form parameters are available in the $_GET and $_POST arrays. When user submits a form then the form parameter is send to the server. Before sending the information, browser encodes it using a scheme called URL encoding. In this scheme, name/value pairs are joined with equal signs (=) and different pairs are separated by the ampersand (&). name1=value1&name2=value2&name3=value3 1.4 Web Technologies - II Introduction to Web Techniques Spaces are removed and replaced with the + character and any other non alphanumeric characters are replaced with a hexadecimal values. After the information is encoded it is sent to the server. There are two HTTP methods that a client can use to pass form data to the server i.e., GET and POST. The method is specified with the method attribute to the form tag. 1.3.1 GET Method [April 16] The GET method sends the encoded user information appended to the page request (to the URL). The page and the encoded information are separated by the ‘?’ character. http://www.test.com/index.htm?name1=value1&name2=value2 The GET method produces a long string that appears in your server logs, in the browser's Location: box. The GET method is restricted to send up to 1024 characters only. Never use GET method if we have password or other sensitive information to be sent to the server. GET cannot be used to send binary data, like images or word documents, to the server. The data sent by GET method can be accessed using QUERY_STRING environment variable. The PHP provides $_GET associative array to access all the sent information using GET method. The following example puts the source code in test.php script:

Use Quizgecko on...
Browser
Browser