Subject Name: Advanced Web Programming Subject Code: (13MCA43) 1. what is PHP? Discuss different control statements

Similar documents
Copyright 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley. Chapter 11 Introduction to PHP

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

COMP284 Scripting Languages Lecture 11: PHP (Part 3) Handouts

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

home.php 1/1 lectures/6/src/ include.php 1/1 lectures/6/src/

PhpT Point, Simply Easy Learning

PHP INTERVIEW QUESTION-ANSWERS

Course Topics. IT360: Applied Database Systems. Introduction to PHP

PHP Introduction. Some info on MySQL which we will cover in the next workshop...

Course Topics. The Three-Tier Architecture. Example 1: Airline reservations. IT360: Applied Database Systems. Introduction to PHP

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

Lecture 12. PHP. cp476 PHP

M275 - Web Development using PHP and MySQL

PHP Hypertext Preprocessor

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

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

Shankersinh Vaghela Bapu Institue of Technology

Important Points about PHP:

USQ/CSC2406 Web Publishing

Enterprise Knowledge Platform Adding the Login Form to Any Web Page

Controlled Assessment Task. Question 1 - Describe how this HTML code produces the form displayed in the browser.

CERTIFICATE IN WEB PROGRAMMING

Final Exam. IT 3203 Introduction to Web Development. Rescheduling Final Exams. PHP Arrays. Arrays as Hashes. Looping over Arrays

PHP 7.1 and SQL 5.7. Section Subject Page

COMP519 Web Programming Lecture 27: PHP (Part 3) Handouts

CPSC 481: CREATIVE INQUIRY TO WSBF

Lab 4: Basic PHP Tutorial, Part 2

(Refer Slide Time: 01:12)

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

Server-side Web Development (I3302) Semester: 1 Academic Year: 2017/2018 Credits: 5 (50 hours) Dr Antoun Yaacoub

UNIT-VI CREATING AND USING FORMS

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

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

Web Site Development with HTML/JavaScrip

CS6501 IP Unit IV Page 1

Princeton University COS 333: Advanced Programming Techniques A Subset of PHP

Lecture 2 Unix and PHP. INLS 523 Web Databases Spring 2013 Rob Capra

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

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

COM1004 Web and Internet Technology

Database Connectivity using PHP Some Points to Remember:

Web Programming 4) PHP and the Web

Web Programming Paper Solution (Chapter wise)

Get in Touch Module 1 - Core PHP XHTML

"Charting the Course... Intermediate PHP & MySQL Course Summary

SECTION 2: PROGRAMMING WITH MATLAB. MAE 4020/5020 Numerical Methods with MATLAB

CITS1231 Web Technologies. PHP s, Cookies and Session Control

Understanding Basic SQL Injection

Spring 2014 Interim. HTML forms

LESSON 3. In this lesson you will learn about the conditional and looping constructs that allow you to control the flow of a PHP script.

IEEM 230. PHP Basics, Part IV. Objectives of the lab:

Princess Nourah bint Abdulrahman University. Computer Sciences Department

WEB APPLICATION ENGINEERING II

Server-side Web Development (I3302) Semester: 1 Academic Year: 2017/2018 Credits: 4 (50 hours) Dr Antoun Yaacoub

Dynamic Form Processing Tool Version 5.0 November 2014

Part A Short Answer (50 marks)

Starting To Write PHP Code

Mount Saint Mary College, Newburgh, NY Internet Programming III - CIT310

PES DEGREE COLLEGE BANGALORE SOUTH CAMPUS 1 K.M. before Electronic City, Bangalore WEB PROGRAMMING Solution Set II

cis20.2-spring2010-sklar-lecii.4 1

PHP: File upload. Unit 27 Web Server Scripting L3 Extended Diploma

Flow Control. Copyleft 2005, Binnur Kurt

Executing Simple Queries

COMS 469: Interactive Media II

Web development using PHP & MySQL with HTML5, CSS, JavaScript

Arithmetic and Assignment Operators

1 Explain the following in brief, with respect to usage of Ajax

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

PHP 1. Introduction Temasek Polytechnic

Web Programming. Dr Walid M. Aly. Lecture 10 PHP. lec10. Web Programming CS433/CS614 22:32. Dr Walid M. Aly

CGI Programming. What is "CGI"?

Creating HTML files using Notepad

Database Systems Fundamentals

DC71 INTERNET APPLICATIONS JUNE 2013

ABOUT WEB TECHNOLOGY COURSE SCOPE:

FILE TYPES 1/2/12 CHAPTER 5 WORKING WITH FILES AND DIRECTORIES OBJECTIVES. Binary. Text PHP PROGRAMMING WITH MYSQL, 2ND EDITION

Autopopulation; Session & Cookies

Mini-Matlab Lesson 5: Functions and Loops

Introduction. This course Software Architecture with Java will discuss the following topics:

Chapter 15 Java Server Pages (JSP)

PHP can also increase your productivity enormously, both in development time and maintenance time.

DC71 INTERNET APPLICATIONS DEC 2014

Setting Up a Development Server What Is a WAMP, MAMP, or LAMP? Installing a WAMP on Windows Testing the InstallationAlternative WAMPs Installing a

INTERNET PROGRAMMING. Software Engineering Branch / 4 th Class Computer Engineering Department University of Technology

CLIL-4-PHP-4. Files - part 2. There are three functions that allow you to work more intimately with the contents

Hyper- Any time any where go to any web pages. Text- Simple Text. Markup- What will you do

Best PHP Training in PUNE & Best PHP Training Institute in MAHARASHTRA

Introduction. Literature: Steelman & Murach, Murach s Java Servlets and JSP. Mike Murach & Associates Inc, 2003

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

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

Form Processing in PHP

4th year. more than 9 years. more than 6 years

JavaScript Functions, Objects and Array

Advanced HTML 5.1 INTRODUCTION 5.2 OBJECTIVES

Introduction to Databases. Key Concepts. Calling a PHP Script 5/17/2012 PHP I

Web Focused Programming With PHP

UNIT I Java Bean, HTML & Javascript

CS105 Perl: Perl CGI. Nathan Clement 24 Feb 2014

PHP with data handling

CS Homework 6. Deadline. Purpose. How to submit. Important notes. Problem 1. Spring CS Homework 6 p. 1

Transcription:

PES Institute of Technology, Bangalore South Campus (Formerly PES School of Engineering) (Hosur Road, 1KM before Electronic City, Bangalore-560 100) Dept of MCA INTERNAL TEST (SCHEME AND SOLUTION) 2 Subject Name: Advanced Web Programming Subject Code: (13MCA43) 1. what is PHP? Discuss different control statements PHP is mainly focused on server-side scripting, so you can do anything any other CGI program can do, such as collect form data, generate dynamic page content, or send and receive cookies. But PHP can do much more. if, elseif, else if ( ) elseif ( ) else switch switch ( ) case condition1 break; case condition2 break; while Syntax: while (condition) do do while (condition) for Example use of the for statement: for ( $n = 1; $n < 10; $n++) echo "$n<br>"; foreach

Versions of PHP prior to version 4 do not support the foreach statement. The following code should list the contents of the array. $tree = array("trunk", "branches", "leaves"); foreach ($tree as $part) echo "Tree part: $part "; break Is used to end the execution of a for, switch, or while statement continue This statement is used to skip the rest of the current loop. for ( $n = 1; $n < 10; $n++) echo "$n<br>"; if ($n == 5) continue; echo "This statement is skipped when $n = 5.<BR>"; 2. Pattren Matching in PHP Regular expressions are nothing more than a sequence or pattern of characters itself. They provide the foundation for pattern-matching functionality. Using regular expression you can search a particular string inside a another string, you can replace one string by another string and you can split a string into many chunks. PHP offers functions specific to two sets of regular expression functions, each corresponding to a certain type of regular expression. You can use any of them based on your comfort. POSIX Regular Expressions PERL Style Regular Expressions POSIX Regular Expressions The structure of a POSIX regular expression is not dissimilar to that of a typical arithmetic expression: various elements (operators) are combined to form more complex expressions. The simplest regular expression is one that matches a single character, such as g, inside strings such as g, haggle, or bag. Lets give explanation for few concepts being used in POSIX regular expression. After that we will introduce you with regular expression related functions. 1. preg_match() The preg_match() function searches string for pattern, returning true if pattern exists, and false otherwise. 2 preg_match_all() The preg_match_all() function matches all occurrences of pattern in string. 3 preg_replace() The preg_replace() function operates just like ereg_replace(), except that regular expressions can be used in the pattern and replacement input parameters.

4 preg_split() The preg_split() function operates exactly like split(), except that regular expressions are accepted as input parameters for pattern. 3. Develop an application to track users using cookie $name = $_POST['user']; $pwd = $_POST['pwd']; if ($_POST['on']) if ($name && $pwd) $content = $name."&". $pwd; setcookie("userdetails",$content, time()+120); elseif ($_POST['off']) setcookie("userdetails", ''); <html> <head> <title> Access Control with Cookie </title> </head> <body> <h1> Access Control with cookie </h1> if ($_POST['_check_']) checkform(); else printform(); function checkform() global $name,$pwd; if ($_POST['show']) echo "<h3> cookie contain ". $_COOKIE["UserDetails"]."<h3>";

else if(!$name!pwd) echo "<h3> Please enter usename and password </h3>"; else echo "<h3> you submitted $name and $pwd<h3>"; printform(); //checkform function printform() $thisurl = $_SERVER[PHP_SELF]; echo <<<_DONE <form action="$thisurl" method="post"> <table> <td> Enter your Name </td> <td><input type="text" length="20" name="user"></td> <td> password </td> <td><input type ="password" length="10" name="pwd"></td> <td><input type="submit" name="on" value =" Log On"/></td> <td><input type="submit" name="off" value =" Log Off"/></td> <td colspan="2" align="center"> <input type="submit" name="show" value="show the cookie" /> </td> <input type = "hidden" name="_check_" value="1" /> </table> </form>

_DONE; </body> </html> 4. Explain functions in PHP PHP functions are similar to other programming languages. A function is a piece of code which takes one more input in the form of parameter and does some processing and returns a value. You already have seen many functions like fopen() and fread() etc. They are built-in functions but PHP gives you option to create your own functions as well. There are two parts which should be clear to you Creating a PHP Function Calling a PHP Function In fact you hardly need to create your own PHP function because there are already more than 1000 of built-in library functions created for different area and you just need to call them according to your requirement. Creating PHP Function Its very easy to create your own PHP function. Suppose you want to create a PHP function which will simply write a simple message on your browser when you will call it. Following example creates a function called writemessage() and then calls it just after creating it. Note that while creating a function its name should start with keyword function and all the PHP code should be put inside and braces as shown in the following example below <html> <head> <title>writing PHP Function</title> </head> <body> /* Defining a PHP Function */ function writemessage() echo "You are really a nice person, Have a nice time!"; /* Calling a PHP Function */ writemessage(); </body> </html> This will display following result You are really a nice person, Have a nice time!

4. b. Write a note on file system in PHP Opening a file Reading a file Writing a file Closing a file Opening and Closing Files The PHP fopen() function is used to open a file. It requires two arguments stating first the file name and then mode in which to operate. Files modes can be specified as one of the six options in this table. Mode Purpose r Opens the file for reading only. Places the file pointer at the beginning of the file. r+ Opens the file for reading and writing.places the file w pointer at the beginning of the file. Opens the file for writing only.places the file pointer at the beginning of the file. If files does not exist then it attempts to create a file. w+ Opens the file for reading and writing only.places the file pointer at the beginning of the file. If files does notexist then it attempts to create a file. a Opens the file for writing only.places the file pointer at the end of the file.if files does not exist then it attempts to create a file. a+ Opens the file for reading and writing only.places the file pointer at the end of the file.if files does not exist then it attempts to create a file. fclose() function Reading a file Once a file is opened using fopen() function it can be read with a function called fread(). This function requires two arguments. These must be the file pointer and the length of the file expressed in bytes. Here are the steps required to read a file with PHP. Open a file using fopen() function. Get the file's length using filesize() function. Read the file's content using fread() function. Close the file with fclose() function. The following example assigns the content of a text file to a variable then displays those contents on the web page. //file1.php <html> <head> <title>reading a file using PHP</title> </head> <body> $filename = "tmp.txt"; $file = fopen( $filename, "r" ); if( $file == false ) echo ( "Error in opening file" );

exit(); $filesize = filesize( $filename ); $filetext = fread( $file, $filesize ); fclose( $file ); echo ( "File size : $filesize bytes" ); echo ( "<pre>$filetext</pre>" ); </body> </html> WRITING A FILE \\ File2.PHP $filename = "/home/user/guest/newfile.txt"; $file = fopen( $filename, "w" ); if( $file == false ) echo ( "Error in opening new file" ); exit(); fwrite( $file, "This is a simple test\n" ); fclose( $file ); 5. Write a program to track users using session tracking mechanism > session_start(); $name = $_POST['user']; $pwd = $_POST['pwd']; if ($_POST['on']) if ($name && $pwd) $_SESSION['user'] = $name; $_SESSION['pwd'] = $pwd; $_SESSION['counter'] += 1; elseif ($_POST['off']) unset($_session['user']); unset($_session['pwd']); unset($_session['counter']); <html> <head><title> acess control using session </title></head> <body> <h1> access control with sessions </h1> if ($_POST['_check_']) checkform(); else printform(); function checkform()

global $name,$pwd; if ($_POST['show']) echo "<h3> session contains ". $_SESSION['user']. " and ". $_SESSION['pwd']. "<h3>"; echo "<h3> you have logged on ". $_SESSION['counter']. " times </h3>"; else if (!$name $pwd ) echo "<h3> please enter user name and pw </h3>"; else echo "<h3> you have entered $name and $pwd <h3>"; printform(); // checkform function printform() $thisurl = $_SERVER[PHP_SELF]; echo <<<_DONE <form action="$thisurl" method="post"> <table> <td> Enter your Name </td> <td><input type="text" length="20" name="user"></td> <td> password </td> <td><input type ="password" length="10" name="pwd"></td> <td><input type="submit" name="on" value =" Log On"/></td> <td><input type="submit" name="off" value =" Log Off"/></td> <td colspan="2" align="center"> <input type="submit" name="show" value="show the Session" /> </td> <input type = "hidden" name="_check_" value="1" /> </table> </form> _DONE; </body> </html> 7. Write a program create XHTML form with Name, address line1, address line2 and email text fields. On submitting, store the values in MySQL table. Retrieve and display the data based on name. Refer lab-2 program in Lab manual