0% found this document useful (0 votes)
2K views

Aakash PHP Complete Solved Solutions For Previous Year Question Papers of PHP Web Based

Pyq for php for bca students sem 2 ipu

Uploaded by

ARPIT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
2K views

Aakash PHP Complete Solved Solutions For Previous Year Question Papers of PHP Web Based

Pyq for php for bca students sem 2 ipu

Uploaded by

ARPIT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 96
on END TERM EXAMINATION [DEC. 2015] FIFTH SEMESTER [BCA] WEB BASED PROGRAMMING [BCA-313] ‘Time : 3 hes. MM. : 76 Note: Attempt any five questions including Q. no. which is compulsory, Select one question from each unit. Q.1. (@) Differentiate between static and dynamic web page Ans. Refer Q. 1. (d) of End Term Examination 2017. Q. 1. (b) Differentiate between mysql_fetch_object and la porenpine Ans. mysql_fetcl >> Fetch a result row as associative and numeric array mysql fetch, object Sel the current row ofa result set as an object mysql_fetch -object0) is similar to mysql_fetch_array(), with one difference - an object is returned, instead of an array. Q. L. (©) Differentiate between Split and Explode. Ans. The split() function splits the string into an array using a regular expression and returns an array. PHP split function takes three arguments, first one takes pattern regular expression which is case sensitive, second is input string and thirst one is for limit: If the limit is set, the returned array will contain a maximum of limit elements with the last element containing the whole rest of string. split(*:”, “this:is:a:string”); /returns an array that contains this, is, a, string. Output: 1 Array ( 2(0] = This, 3 [1] >is, 4[2]>a, 5 [3] > string } ‘The php explode() function splits the string using delimiter and returns an array. PHP explode function takes three argument, first one takes delimiter as a argument, second one is target string and third one is limit: If limit is set and positive, the returned array will contain a maximum of limit elements with the last element containing the rest of string. 1 explode (“this”, “this is a string”); /returns an array that contains array “isa string Output —_array({0] => “is a string”) Q. 1. (d) Describe functions STRSTR( and STRISTR(Q) Ans. strstr() and stristr both are used to find the first occurence of the string. stristr() is case insensitive and strstr( ) is case sensitive. strstr() — Find first occurrence of a string Syntax: strstr ($string, string) Example: ; Output:Ail.com es —- 22-2015 Fifth Semester, Web Based Programming stristr() ~ Find first occurrence of a string (Case-insensitive) Syntax: stristr ($string, string) Example: ‘Welcome to my home page! hl>

Some text,

The require() Function ‘The require() function takes all the text in a specified file and copies it into the file that uses the include function. If there is any problem in loading a file then the require() function generates a fatal error and halt the execution of the script. So there is no difference in require() and include() except they handle error conditions. Itis recommended to use the require() function instead of include(), because scripts should not continue executing if files are missing or misnamed. ‘Syntax: require ‘filename’, Q. 1. G) What is printf function and difference between echo and print statement in PHP? Ans. Refer Qno.1.(b) of end term exam 2017 Q. 1. G) Explain PHP with its feature? ‘Ans. It is open source scripting language so you can free download this an PHPis a server site scripting language. Itis open source scripting language. It is used all over the world. Itis faster than other scripting language. Some important! = Fifth Semester, Web Based Programming 4-2015 Platform Independent Famonde one Monitoring Features of php: It is most popular and frequently used worldwide scripting the main reason of popularity is; It is open source and very simple. % Simple ; Faster; Interpreted; Open Source; Case Sensitive ; Simplicity ; Efficiency «Platform Independent; Security; Flexibility; Familiarity; Error Reporting ; Loosely ‘Typed Language; Real-Time Access Monitoring ‘Simple: It is very simple and easy to use, compare to other scripting language itis ‘very simple and easy, this is widely used all over the world. Interpreted: Itis an interpreted language, ie. there is no need for compilation. Faster: It is faster than other scripting language e.g. asp and jsp- Open Source : Open source means you no need to pay for use php, download and use. Platform Independent: PHP code will be run on every platform, Linux, Unix, Mac OSX, Windows. ~ Gase Sensitive: PHP is case sensitive scripting language at time’of variable else, while, echo, etc.), classes, functions, and you can free "declaration. In PHP, all keywords (e.. defined functions are NOT case-sensitive. ‘Access Monitoring: PHP provides access logging by creating the of recent accesses for the user. ‘Typed Language: PHP supports variable usage without declaring its data ‘taken at the time of the execution based on the type of data it has onits the different functions for Sorting an Array? potions: LP. University-[BCA}-Akash Books 2015-5 Q. 2.(b) Difference between Client side scripting with server side scripting Ans. Client-side Environment : The client-side environment used to run seripts is usually a browser. The processing takes place on the end users computer. The source code is transferred from the web server to the users computer over the internet and run directly in the browser. The scripting language needs to be enabled on the client computer. Sometimes if a user is conscious of security risks they may switch the scripting facility off. When this is the case a message usually pops up to alert the user when script is attempting to run. Server-side Environment ; The server-side environment that runs a scripting language is a web server. A user's request is fulfilled by running a script directly on the web server to generate dynamic HTML pages. This HTML is then sent to the client browser, It is usually used to provide interactive web sites that interface to databases or other data stores on the server. ‘This is different from client-side scripting where scripts are run by the viewing web browser, usually in JavaScript. The primary advantage to server-side scripting is the ability to highly customize the response based on the user's requirements, access rights, or queries into data stores. Comparison between client-side and server-side scripting Server-side scripting * Response from a server-side script is slower because the scripts are processed remotely. ee Examples for server side scripting languages: PHP, JSP, ASP, Asp. Net, Ruby, ete. + Server side scripting is used to connect to the databases that is on web server. Client-side scripting ‘+ Response from a client-side seriptis faster because the scripts are processed on the local computer. * Client side scripting languages: Javascript, VB script, ete. + Cannot connect to the databases on the web server. Q. 3. (a) Explain HTML and differentiate GET and POST form submission methods with example? Ans. Hypertext Markup Language (HTML) is the standard markup language for creating web pages and web applications. With Cascading Style Sheets (CSS) and JavaScript. HTML elements are the building blocks of HTML pages. With HTML constructs, images and other objects such as interactive forms may be embedded into the rendered page. HTML provides a means to create structured doc b structural semantics for text such as headings, paragraphs, lis items. HTML elements are delineated by tags, written using. as and directly introduce content into as

surround and provide information about document tags as sub-elements. Browsers do not display the HTML tag the content of the page. HTML can embed programs written in a scripting which affects the behaviour and content of web pages. n of content. 6-2015, Fifth Semester, Web Based Programming * GET * POST ‘The GET Method GET is used to request data from a specified resource. GET is one of the most common HTTP methods. * GET requests can be cached * GET requests remain in the browser history * GET requests can be bookmarked P * GET requests should never be used whemdealing with sensitive data * GET requests have length restrictions * GET requests is only used to request data (not modify) ‘The POST Method ft POST is used to send data to a server to create/update a resource. * POST requests are never cached ‘+ POST requests do not remain in the browser history * POST requests cannot be bookmarked + POST requests have no restrictions on data length ' ‘The PHP superglobals $_GET and $_POST are used to collect form-data. Example: of post Welcome. php code is below Welcome
‘Your email address is: Now using welcome.php below: action="welcome.php” method="post”>
LP, University-(BCA}-Akash Books 2015-7

Name:
E-mail:
put type="submit"> Q.3.(b) Explain and compare the Local and Remote Server. Ans. Ifyou are referring to a Local Server, this means that you have a server setup on your current machine, When the server is Remote, this just means that it is on another computer. a ‘You may have heard the phrase, "Working Remotely.” What this means is that the F person will not be working in the office, instead they could be working at home or from their favourite corner coffee shop. So since that person is away from the office, they are considered “Remote.” In the same case if a server hosting your files is not in-house or on your computer, it is considered to be a Remote Server. ’ What happens when you visit a web page in your browser, Well, your computer needs to contact a (remote) server on the web and then send the data back to your computer: Your browser connects to a server and requests a page. ‘The server sends back the requested page Your machine Server Machine running a Web running a Web browser Serwer But when you are running a local server, your computer contacts itself since it is | running a local server and returns the data back to the browser: Your browser connects to your local server LP, University-[BCA]-Akash Books 2015-11 familyName(“Santosh”, “1987 familyname(“Sonu”, “1982"); & Output is ‘Santosh singh born in 1987 Sonu singh born in 1982 UNIT-IIT Q.6.(a) Explain Application state and write a program to demonstrate Cookies "Ans. When you work with an application, you open it, do some changes, and then you close it, This is much like a Session, The computer knows who you are. It knows {hen you start the application and when you end, But on the internet there is one problem: the web server does not know who you are or what you do, because the HTTP address doesn’t maintain state. ‘Session variables solve this problem by storing user information to be used across multiple pages (e.g. username, favorite color, etc). By default, session variables last until the user closes the browser. ‘So; Session variables hold information about one single user, and are available to all pages in one application. In PHP, session management is used to help web applications maintain their state across several HTTP requests when needed. For Cookies: Refer Q. 6. (b) of End Term Examination 2017. Q. 6.(b) Write a program to copy the content of one file to another file. Ans. Copying Files r PHP copy() is used to create a clone of myfile.txt. Type in below example and save it as copyfile.php, then call up the program in our browser. eg. Q.7.(a) Write a program to send Email using PHP. Ans. Refer Q. No 1.(i) of End Term Examination 2017 Q.7. (b) Explain session with its features and demo} 8.(a) How can we increase execution time of a Refer to Q.8(a) End Term 2017. 12-2016 Fifth Semester, Web Based Programming ir a tag. In this example, we point to this file , Hace ec data: Ifyou wish to use another PHP fle to process form dary Sel that with the filename of your choice. Then, we can use the super global yg,P&ee $_REQUEST to collect the value of the input field: variably 4 ; Q. 1. (©)Whatis the difference between array combine and array merges? Ans. array_merge() : array_merge() function merges the elements of one or mare into a single resultant array in such a way, So that the values of one array append ‘end of previous ones. We can pass one or more arrays as parameters. ntax : array_merge(array1array2. Specifies an input array. (Required) Specifies an input array. (Optional) combine(): array_combine() function takes two arrays of same length and w resultant array, using one array as keys and other array for values. The the combined array on success and FALSE if the length of both arraj “POST”) [ LP. University-{BCA]-Akash Books 2016-3 Ithas two: ions, include and include_once. Include_once is ignored by the PHP variations, interpreter if the file to be included. ‘The include statement has the following syntax HERE, + “require/require_once” is the statement that includes file * “file name” is the name of tne file to be included. ‘The difference between include / require Include Require Issues a warning when an error occurs | Does not issue a warning ‘Execution of the script continues when | Execution of the script an error occurs error occurs. + Generally, its recommended using the include statement sf occurs, execution of the script continues to display the webmast contact us page. ‘* The require statement should be used if the entire script 4-2016 Fifth Semester, Web Based Programming Itis important to notice that header) must be catled bet fore any actual i sent (In PHP 4 and later, yourean use output buffering to solve this probe ys ets Syntax header (string,replace,http_response_code) Q. 1. © Write a PHP script to send a mail. Ans. Refer Q. 1. (i) of End Term Examination 2017, Q. 1. (@) What is maintaining state? How can we create, Ans. Refer Q. 6. (b) of End ‘Term Examination 2017. : HTTP is a stateless access and delete a Protocol, which means that once a web ge, the connection between the two goes recognize that a sequence of requests in the cart when he decides to check out, ‘To get around the Web's lack of state, programmers have come up with many tricks to keep track of state information between requests (also known us session tracking ). One such technique is to use hidden form fields to pass around information Pap treats hidden form fields just like normal form fields, so the values are available in the $_GET and $_POST arrays. Using hidden form fields, you can pass around the entire ‘contents of a shopping cart. However, a more common technique is to assign each user a unique identifier and pass the ID around using a single hidden form field, While hidden form fields work in all browsere, they work only for a sequence of dynamically generated | forms, so they aren't as generally useful as some other techniques. ] Another technique is URL rewriting, where every local URL on which the user might) _ lick is dynamically modified to include extra information. This extra information ig ‘often specified as a parameter in the URL. For example, if you assign every ‘ID, you might include that ID in all URLs, as follows: ‘http:/www.example.com/catalog.php?userid=123 - Ifyou make sure to dynamically modify all local links to include a user ID, you can ‘keep track of individual users in your application. URL rewriting works for all nically generated documents, not just forms, but actually performing the rewriting user a unique technique for maintaining state is to use cookies. A cookie is a bit of ‘that the server can give to a client. On every subsequent request the client at information back to the server, thus identifying itself. Cookies are useful .ation through repeated visits by a browser, but they're not without The main problem is that some browsers don’t support cookies, row that do, the user can disable cookies. So any application that state maintenance needs to use another technique as a fallback 38 cookies in more detail shortly. lication, as well as in different PHP’ ion-tracking mechanism us st problems that require state, taking Books 2016-5 Q.1. (h) What is Jugal o ‘Ans. Refer Q. 1. (e) of End Term Examination 2017. @.1. @) Difference between echo and print and == and == =in PHP. ‘Ans, Refer Q. 1. (b) of End Term Examination 2017. ‘Two of the many comparison operators used by PHP are ‘=='(i.e. equal) and ‘=== (i.e. saenticaly. The difference between the two is that =~’ should be used to check if the values xegpe bwo operands are equal or not. On the other hand, “===! checks the values as well ‘as the type of operands. Let me explain more using some examples: == (equa: "; echo “Value of b: $b
”; $ar$a+$b; echo “Value of a: $a
"; ‘echo “Value of b: $h
"; > 5. (b) What do you mean by variables? Write a menu Driven program to implement a calculator. Ans. Variables ‘A variable can have a short name (like x and y) or a more descriptive name (age, carname, total_volume). Rules for PHP variables: + Avvariable starts with the $ sign, followed by the name of the variable + Avariable name must start with a letter or the underscore character * Avariable name cannot start with a number + Avariable name can only contain alpha-numeric characters and underscores (A- 4, 0-9, and _) * Variable names are case-sensitive ($age and $AGE are two diffe Calculator in PHP using Drop down Menu Simple Calculator LP. University-{BCA}-Akash Books 2016-11
efieldset> Simple Calculator ” autofocus> select names"opt_math">