0% found this document useful (0 votes)
47 views

Phppaper2 Merged

Phppaper

Uploaded by

jatavravi3653
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)
47 views

Phppaper2 Merged

Phppaper

Uploaded by

jatavravi3653
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/ 46
b) | Explain Indexed array and associat examples. Ans, | © Inindexed arrays the value is accessed using indexes 0,1,2 et. = ‘These types of arrays can be used to store any type of el ve arrays with suitable | 4M nts, but an index is always a number. By default, the index starts at | sxplanation zero. These arrays can be created in two different ways as shown | of each array in the following with suitable = Array initialization ‘example 2M First method Scolors = array("Red", "Green", "Blue"); Second method Scolors[0] = "Rei Scolors{1] = "Gree Scolors{2] = "Blue"; Example: 95, "Physics'=>90, “Computer"=>98): Second method to create an associate array. Sstudent_two["Maths"] = 95: Sstudent_twof"Physies"] = 90; Sstudent_two["Chemistry"] = 96; Sstudent_twof"English"} = 9” Sstudent_two["Computer"] = 98; Example Correct Code ~ to set cookie « iM "; echo "Value is: ". $_COOKIE|$cookie_name]; Output: Cookie ‘usern Value is: abe PHP program to modify cookies if(lisset($_COOKIE["user"])) ( echo "Sorry, cookie is not found!"; eli echo "
Cookie Value: " $_COOKIE["user"}; ) Page 19/22 MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC - 27001 - 2005 Certified) WINTER - 2022 EXAMINATION MODEL ANSWER Subject: Web Based Application Development Using PHP (Elect-II) Subject Code:| 22619 Output: ¢) | i) State the use of serialization. 6M ii) State the query to insert data in the database. i) Use of serializati Seriotionton Serializing an object’ means converting it to a bytestream | ‘explanation representation that can be stored in a file, Serialization in PHP with mostly auto! it requires little extra work from you, beyond | example- 3M calling the serialize () and unserialize( } functions. Serialize() : © The serialize() converts a storable representation of a value. © The serialize() function accepts a single parameter which is the data we want to serialize and returns a serialized string, © A serialize data means a sequence of bits so that it can be stored a file, a memory buffer or transmittedacross a network connection link. It is useful for storing or passing PHP values around without losing their type and structure. Example: "); $us_data=unserialize($s_data); ‘Welcome’, ‘to’, PHP"); Page 21/22 MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC - 27001 - 2005 Cer ied) WINTER - 2022 EXAMINATION MODEL ANSWER 22619 Subject: Web Based Application Development Using PHP (Elect-II) _ Subject Code: print_r($us_data); Outputza:3 7:" Welcome" 3i:138:2:"to" si:2; 3 Correct Array ( [0] => Welcome [1] => to [2] => PHP ) example of insert query- 3M ii) Query to insert data in the database <2php require_once ‘ogin.php'; Sconn = newmysqli($hostname, $username, $password,Sdbname); Squery = "INSERT INTO studentinfo(rollno,name,percentage) VALUES ((CO103',"Yogita Khandagale’,98.45)", $result = Sconn->query(Squery); if (!Sresult) die ("Database access failed: " . $conn->error); else echo "record inserted successfully"; > Output: record inserted successfully ¢) Ans. Define serialization and explain it with example 4M Definition: The serialize() function converts a storable representation of a value, Correct To serialize data means to convert a value to a sequence of bits, so that it can tee be stored in a file, a memory buffer, or transmitted across a network. suitable Syntax example 2M serialize(value); Example: Output: a:3: {is 23:"Red"si: 1;s:5:"Green" ;i:231:4044; } g) | How to create session variable in PHP? 2M Ans. |e Session variable can be set with a help of a PHP global variable: IM for $_SESSION. explanatio ® Data in the session is stored in the form of keys and values pair. n e We can store any type of data on the server, which include IM for arrays and objects. correct * For example, we want to store username in the session so it can syntax / be assessed whenever it is required throughout the session, example www.diplomachakhazana.in Page 3/29 MAHARASHTRA [ATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC - 27001 - 2005 Certified) SUMMER - 2022 EXAMINATION MODEL ANSWER 22619 Subject: Web based Application Development using PHP Subject Code: <2php $_SESSION["uname"]="Customer! "5 $_SESSION['fcolor"]="RED"; echo "The session variable are set with values"; » (Any other correct example can be consider and consider any (vo user input validation) Attempt any TWO of the following 2 a) | Explain different loops in PHP with example. ot Ans. | while loop: If the expression/condition specified with while | 1M for evaluates to true then the statements inside loop executes and | explanatio control i transferred back to expression/condition. The process of | m and ‘evaluation and execution IM for Example: example ‘ imagestring($image, 5, 180, 100, 2>eksforGeek imagestring($image, 3, 160, 120, A com ter header("Content-T z image/png"); imagepng($image) ; imagedestroy($image); GeeksforGeeks fi computer science portal 1. Attempt any FIVE of the following: 10 a) List any four data types of PHP. 2M Ans. | ® boolean Any four ® integer wypes 2M © float each © string © array © object ® resource e NULL b) Define Array. State its example. 2M Ans. | Definition:An array is a special variable, which can hold more than Definition one value at a time. IM Page 1/22 MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) ITEC - 27001 - 2005 Certified) WINTER -— 2022 EXAMINATION MODEL ANSWER Subject: Web Based Application Development Using PHP (Elect-I1) Subject Code: Example: D)Indexed array: $colors = array("Red", "Green", "Blue"); Any one example IM 2)Associative array: $student_one = array("Maths"=>95, "Physics"=>90, "Chemistry"=>96, "English"=>93, "Computer"=>98); 3)Multidimensional array $movies ray( "comedy" =>array("Pink Panther", "John English", "See no evil hear no evil"), ion" =>array("Die Hard", "Expendables"," Inception"), =>array("The Lord of the rings") Ans. State role of GET and POST methods i)Get method: It processes the client request which is sent by the client, using the HTTP get method.Browser uses get method to send request. ii)Post method It Handles request in servlet which is sent by the client. If a client is entering registration data in an html form, the data can be sent using post method. 2M. IM for each method a) Ans. Attempt any THREE of the following: Explain the use of break and continue statements. Break statement:-break keyword is used to terminate and transfer the control to the next statement when encountered inside a loop or switch case statement. Syntax: if (condition) { break; } Example: "; } echo " Terminate the loop at $a number"; > ii)Continue Statement It is used to skip the execution of a particular statement inside the loops. if (condition) { continue; } Example: "; echo "end"; » ce) Define Introspection. Explain it with suitable example Ans. | Introspection is the ability of a program to examine an object's characteristics, such as its name, parent class (if any), properties, and | é/inition methods. With introspection, we can write code that operates on any 1” class or object. We don't need to know which methods or properties are defined when we write code; instead, we can discover that informationat runtime, which makes it possible for us to write generic debuggers, serializers, profilers, etc. Example:- child class methods: "; print_r(get_class_methods('childcl echo"
child class variables: print_r(get_clas: "childe echo"
parent class variable: print_r(get_class_vars(‘parentclass’)); echo"
parent print_r(get_parent_class(‘childclass’); //object introspectior echo"
is object: "; print_r(is_object($obj)) echo"
object of a cl print_r(get_class($obj)); echo"
object variables: "; print_r(get_object. vars($obj)); echo"
methods exi: print_r(method_exists($ > exists(‘parentclass’)); b) Ans. Write a program for cloning of an object. (Any other correct program shall be considered) name=$nm,; $this->rollno=$rn; ) function display() { echo "
name = echo "
rollno = ) ) $s1 = new student(); $s1->getdata("abe",1); $s1->display(); $s2 = clone $s1; “
Cloned object data "; isplay(); "Sthis->name; Sthis->rollno; 4M Correct program 4M d) Explain queries to update and delete data in the database. 4M. Ans. | Update data : UPDATE query Update command is used to change / update new value for field in | Explanation row of table. It updates the value in row that satisfy the criteria given | °f Update in query. query 2M The UPDATE query syntax: UPDATE Table_name SET field_name=New_value WHERE field_name=existing_value Example : UPDATE student SET rollno=4 WHERE name="abc' In the above query, a value from rollno field from student table is updated with new value as 4 if its name field contains name as ‘abe’. Delete data: DELETE query Delete command is used to delete rows that are no longer required Pxplanation from the database tables. It deletes the whole row from the table. Delete query The DELETE query syntax: 2M DELETE FROM table_name WHERE some_column = some_value Page 14/22 MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC - 27001 - 2005 Certified) WINTER — 2022 EXAMINATION MODEL ANSWER Subject: Web Based Application Development Using PHP (Elect-II) Subject Code: | _ 22619 [WHERE condition] is optional. The WHERE clause record or records that should be deleted. If the WHE used, all records will be deleted Example :- $sql = "DELETE FROM student WHERE rollno=2"; ecifies which clause is not In the above query, a row from student table is deleted if rollno field contains 2 in that row b) Write a program to connect PHP with MYSQL. Solution]: Susername = "root"; Spassword ="; // Connection Sconn = new mysqli($servername,Susername, $password); // For checking if connection issuccessful or not, if ($conn->connect_error) { die(" Connection failed: ". $conn->connect_error); } echo "Connected successfully"; ” Output: Connected successfully OR 6M Correct syntax 2M Correct code 4M Writing Output is optional Page 16/22 Subject: Web Based Application Development Using PHP (Elect-II) MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC - 27001 - 2005 Certified) WINTER - 2022 EXAMINATION MODEL ANSWER Subject Code: | 22619 Solution2: Create login.php connect_error) die(Sconn->connect_error); if (Sconn->connect_error) { die("Connection failed; " $conn->connect_error); echo "Connected successfully"; s Output: Connected successfully A c) | i) State the use of serialization. 6M ii) State the query to insert data in the database. i) Use of serialization. Serialization Serializing an object means converting it to a bytestream | explanation representation that can be stored in a file, Serialization in PHP is | with mostly automatic, it requires little extra work from you, beyond | «ample: 3M calling the serialize () and unserialize( ) functions. Serialize(Q) : © The serialize() converts a storable representation of a value. © The serialize function accepts a single parameter which is the data we want to serialize and returns a serialized string A serialize data means a sequence of bits so that it can be stored in a file, a memory buffer or transmittedacross a network connection link. It is useful for storing or passing PHP values around without losing their type and structure. Example: "); Sus_data=unserialize($s_data); Page 21/22 MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) ISO/IEC - 27001 - 2005 Certified) WINTER - 2022 EXAMINATION MODEL ANSWER Subject: Web Based App! Development Using PHP (Elect-I) Subject Code: |_22619 print_r(Sus_data); Output: "Welcome’;i:1;8:2:"to" Correct Array ( [0] => Welcome [1] => to [2] => PHP ) example of insert query- 3M ii) Query to insert data in the database <*php require_once ‘login.php’; Sconn = newmysqli(Shostname,Susername, Spassword,Sdbname); Squery = "INSERT INTO studentinfo(rollno,name, percentage) VALUES ((CO103','Yogita Khandagale',98.45)"; Sresult = Sconn->query(Squery): if (1Sresult) die ("Database access failed: " . Sconn->error); else echo "record inserted successfully"; > Output: record inserted successfully d) Ans. Describe the procedure of sending email. 1. PHP mail is the built-in PHP function that is used to send emails from PHP script 2. The mail function accepts the following paramete! a) Email address b) Subject c) Message d) CC or BCC email addresses 3. The PHP mail function has the following basic syntax HERE, a) “$to_email_addré 's the email address of the mail recipient b) “Ssubject” is the email subject c) “$message” is the message to be sent. d) “[Sheaders]” is optional, it can be used to include information such as CC, BCC * CC is the acronym for carbon copy. It’s used when you want to send a copy to an interested person i.e. a complaint email sent to a company can also be sent as CC to the complaints board. 4M Correct procedure 4M Page 6 / 26 MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC - 27001 - 2005 Certified) SUMMER - 2023 EXAMINATION MODEL ANSWER-Only for the Use of RAC Assessors Subject: Web Based Application Development Using PHP (Elect-II) Subject Code: 22619 © BCC is the acronym for blind carbon copy. It is similar to CC. The email addresses included in the BCC section will not be shown to the other recipients. 4. PHP mailer uses Simple Mail Transmission Protocol (SMTP) to send mail. On a hosted server, the SMTP settings would have already been set. The SMTP mail settings can be configured from “php.ini” & “sendemail.ini” file in the PHP installation folder. Php Mail Example Explode function The explode function works on a string. The explode function returns array. The first parameter of the explode function is required, Syntax: array explode(string separator,string string) Example: name=Sname; } funetion display() { echo Sthis->name; } } $si=new student("xy2"); $s1->display(s Destructor: A destructor is the counterpart of constructor. A destructor function is called when the object is destroyed. A destructor function cleans up any resources allocated to an object after the object is destroyed. A destructor function is commonly called in two ways: When a script ends or manually delete an object with the unset() function. The ‘destruct’ method starts with two underscores (_). Syntax :function __destruet() { nC initialization code * ) The type of argument, argument2,.....angumentN are mixed. Page 21/26 mous) (ISOMEC - 27001 - 2005 C ‘ TH MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION ified) SUMMER - 2023 EXAMINATION MODEL ANSWER-Only for the Use of RAC Assessors Subject: Web Based Application Development Using PHP (Blect-11) subject Ce 22619 Example name=$name; } function _destruct() { echo "Destructor is executing " Sthis- ) ) $s1=new student("xyz"); > b) Ans, 1 Write a program to create pdf document in PHP addPage(); $pdf->setFont("Arial", 'IBU', 16); $pdf->settextcolor( 150,200,225); $pdf->cell(40, 10, "Hello Out There!"); $pdf->output(); > 6M Correct logic 3M Correct syntax 3M Ans. What is array? How to store data in array? 1. An array in PHP is an ordered map where a map is a type that associates values to keys. 2. Ways to store an array. Using array variable OR Using array indices $array[] = "Watermelon; Sarray[] = ‘Mango; print_r($array); b 2M IM for definition IM to store data g) | How to create session variable in PHP? 2M Ans. |e Session variable can be set with a help of a PHP global variable: 1M for $_SESSION. explanatio e Data in the session is stored in the form of keys and values pair. n e We can store any type of data on the server, which include IM for arrays and objects. correct e For example, we want to store username in the session so it can syntax / be assessed whenever it is required throughout the session. example www.diplomachakhazana.in Page 3/29 MAHARASHTRA (Autonomous) (ISO/IEC - 27001 - 2005 Certified) SUMMER - 2022 EXAMINATION MODEL ANSWER TE BOARD OF TECHNICAL EDUCATION Subject: Web based Application Development using PHP Subject Code: 22619 d) | Write difference between get() and post() method of form (Any four points) Ans. HTTP GET HTTP POS! In GET method we cannot send large amount of data rather limited data is sent because the request parameter is appended into the URL. In POST method large amount of data can be sent because the request parameter is appended into the body. 4M IM for each correct differentiat ion, any four points www.diplomachakhazana.in Page 6 / 29 2005 Certified) SUMMER = 2022 EXAMINATION MODEL ANSWER Subject: Web based App! ation Development using PHP MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION (Autonomous) (ISO/IEC - 27001 - Subject Code: 22619 GET request is comparatively better than Post so it is used more than the Post request. POST request is comparatively less better than Get so it is used less than the Get request. GET request is comparatively less secure because the data is exposed in the URL bar. POST request is comparatively more secure because the data is not exposed in the URL bar. Request made through GET method are stored in Browser history. Request made through POST method is not stored in Browser history. GET method request can be saved as bookmark in browser. POST method request cannot be saved as bookmark in browser. Request made through GET method are stored in cache memory of Browser. Request made through POST method are not stored in cache memory of Browser. Data passed through GET method can be easily stolen by attackers. Data passed ~~ through POST method cannot be easily stolen by attackers. In GET method only ASCII characters are allowed. In POST method all types of data is allowed. to be considered Subject: Web based Application Development using PHP Subject Code: (Autonomous) (ISO/IEC - 27001 - 2005 Certified) SUMMER - 2022 EXAMINATION MODEL ANSWER 3. Attempt any THREE of the following: 12 a) Define function. How to define user defined function in PHP? 4M Give example. IM for Ans. | Definition: -A function is a block of code written in a program to | definition perform some specific task. They take information as parameters, execute a block of statements IM for or perform operations on these parameters and return the result. A syntax function will be executed by a call to the function. 2M for any Define User Defined Function in PHP: A user-defined function | relevant declaration starts with the keyword function. example Syntax function functionName() { code to be executed; Page 7/29 MAHARASHTRA STATE BOARD OF TECHNICAL EDUCATION 22619 } Example ar echo "
" calling area method for rectat echo (Ss->area(4, 2)); Output: 9.426 48 Here the area() method is created dynamically and executed with the help of magic method _call() and its behavior changes according to the pass of parameters as object. fieni idthieanietiinnestin ontiliiendlls 1. for loop 2. while loop 3. do-while loop 4. foreach loop Let us now learn about each of the above mentioned loops in details: 1. for loop: This type of loops is used when the user knows in advance, how many times the block needs to execute. That is, the number of iterations is known beforehand. These type of loops are also known as entry-controlled loops. There are three main parameters to the code, namely the initialization, the test condition and the counter. Syntax: for (initialization expression; test condition; update ex // code to be executed In for loop, a loop variable is used to control the loop. First initialize this loop variable to some value, then check whether this variable is less than or greater than counter value. If statement is true, then loop body is executed and loop variable gets updated . Steps are repeated till exit condition comes. ° Initialization Expression: In this expression we have to initialize the loop counter to some value. for example: $num = 1; Test Expression: In this expression we have to test the ° condition. If the condition evaluates to true then we will execute the body of loop and go to update expression otherwise we will exit from the for loop. For example: $num otherwise we will exit from the for loop. For example: $num <= 10; o Update Expression: After executing loop body this expression increments/decrements the loop variable by some value. for example: Snum += 2; Example: Output: 10 20 30 40 50 60 Ram Laxman strrev() Function It returns the reversed string of the given string. Syntax strrev(string or variable name); Example: This example illustrates the basic implementation of the strrev() Function in PHP. PHP Output !dlroW olleH trim(), ltrim(), rtrim(), and chop() Functions It removes white spaces or other characters from the string. They have two parameters: one string and another charList, which is a list of characters that need to be omitted. ¢ trim(): Removes characters or whitespaces from both sides. ¢ rtrim() & chop(): Removes characters or whitespaces from the right side. « Itrim(): Removes characters or whitespaces from the left side. ucwords() Function It is used to convert the first character of every word in a string to upper-case. Syntax string ucwords ( $string, $separator ) Parameters This function accepts two parameters out of which the first is compulsory and the second is optional. Both of the parameters are explained below: ¢ $string: This is the input string of which you want to convert the first character of every word to uppercase. ¢ $separator: This is an optional parameter. This parameter specifies a character that will be used as a separator for the words in the input string. For example, if the separator character is ‘|’ and the input string is “Hello|world” then it means that the string contains two words “Hello” and “world”. Example: This example illustrate the basic implementation of the ucwords() Function in PHP. PHP str_replace() Function Itis used to replace all the occurrences of the search string or array of search strings by replacement string or array of replacement strings in the given string or array respectively. Syntax str_replace ( $searchVal, $replaceVal, $subjectVal, $count Parameters This function accepts 4 parameters out of which 3 are mandatory and 1 is optional. All of these parameters are described below: ¢ $searchVal: This parameter can be of both string and array types. This parameter specifies the string to be searched and replaced. * $replaceVal: This parameter can be of both string and array types. This parameter specifies the string with which we want to replace the SsearchVal string. ¢ $subjectVal: This parameter can be of both string and array types. This parameter specifies the string or array of strings that we want to search for SsearchVal and replace with SreplaceVal. ¢ $count: This parameter is optional and if passed, its value will be set to the total number of replacement operations performed on the string SsubjectVal. Example: This example illustrate the basic implementation of the str_replace() Function in PHP. Example: This example illustrate the basic implementation of the str_replace() Function in PHP. PHP strpos() Function This function helps us to find the position of the first occurrence of a string in another string. Syntax strpos(original_str, search_str, start_pos); Parameters Out of the three parameters specified in the syntax, two are mandatory and one is optional. The three parameters are described below: ¢ original_str: This is a mandatory parameter that refers to the original string in which we need to search for the occurrence of the required string. ¢ search_str: This is a mandatory parameter that refers to the string that we need to search. ¢ start_pos: This is an optional parameter that refers to the position of the string from where the search must begin. Example: This example illustrate the basic implementation of the strpos() Function in PHP. PHP PHP strtoupper() and strtolower() Function It returns the string after changing the cases of its letters. ¢ strtoupper(): It returns the string after converting all the letters to uppercase. ¢ strtolower(): It returns the string after converting all the letters to lowercase. Syntax strtoupper (string) strtolower (string) Example: This example illustrates the basic implementation of the strtoupper() and strtolower() Function in PHP. PHP "; echo strtolower($str); > Output: GEEKSFORGEEKS geeksforgeeks Controls used in forms: Form processing contains a set of controls through which the client and server can communicate and share information. The controls used in forms are: ° Textbox: Textbox allows the user to provide single-line input, which can be used for getting values such as names, search menu and etc. ° Textarea: Textarea allows the user to provide multi-line input, which can be used for getting values such as an address, message etc. * DropDown: Dropdown or combobox allows the user to provide select a value from a list of values. ¢ Radio Buttons: Radio buttons allow the user to select only one option from the given set of options. ° CheckBox: Checkbox allows the user to select multiple options from the set of given options. e Buttons: Buttons are the clickable controls that can be used to submit the form. Creating a simple HTML Form: All the form controls given above is designed by using the input tag based on the type attribute of the tag. In the below script, when the form is submitted, no event handling mechanism is done. Event handling refers to the process done while the form is submitted. These event handling mechanisms can be done by using javaScript or PHP. However, JavaScript provides only client-side validation. Hence, we can use PHP for form processing. Form Validation: Form validation is done to ensure that the user has provided the relevant information. Basic validation can be done using HTML elements. For example, in the above script, the email address text box is having a type value as “email”, which prevents the user from entering the incorrect value for an email. Every form field in the above script is followed by a required attribute, which will intimate the user not to leave any field empty before submitting the form. PHP methods and arrays used in form processing are: e isset(): This function is used to determine whether the variable or a form control is having a value or not. ¢ $_GET[]: It is used the retrieve the information from the form control through the parameters sent in the URL. It takes the attribute given in the url as the parameter. ¢ $_POST[]: It is used the retrieve the information from the form control through the HTTP POST method. IT takes name attribute of corresponding form control as the parameter. ¢ $_REQUESTI]: It is used to retrieve an information while using a database. Form Processing using PHP: Above HTML script is rewritten using the above mentioned functions and array. The rewritten script validates all the form fields and if there are no errors, it displays the received information in a tabular form.

You might also like