Q.1 Attempt ANY ONE of The Following (1000 Words) : A. Describe Get and Post Methods of PHP Form With Example
Q.1 Attempt ANY ONE of The Following (1000 Words) : A. Describe Get and Post Methods of PHP Form With Example
The GET method sends the encoded user information appended to the page request. The
page and the encoded information are separated by the ? character.
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 upto 1024 characters only.
Never use GET method if you have password or other sensitive information to be
sent to the server.
GET can't 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.
example by putting the source code in test.php script.
<?php
if( $_GET["name"] || $_GET["age"] ) {
echo "Welcome ". $_GET['name']. "<br />";
echo "You are ". $_GET['age']. " years old.";
exit();
}
?>
<html>
<body>
</body>
</html>
The POST method transfers information via HTTP headers. The information is encoded as
described in case of GET method and put into a header called QUERY_STRING.
The POST method does not have any restriction on data size to be sent.
The POST method can be used to send ASCII as well as binary data.
The data sent by POST method goes through HTTP header so security depends on
HTTP protocol. By using Secure HTTP you can make sure that your information is
secure.
The PHP provides $_POST associative array to access all the sent information using
POST method.
example by putting the source code in test.php script.
<?php
if( $_POST["name"] || $_POST["age"] ) {
if (preg_match("/[^A-Za-z'-]/",$_POST['name'] )) {
die ("invalid name and name should be alpha");
}
echo "Welcome ". $_POST['name']. "<br />";
echo "You are ". $_POST['age']. " years old.";
exit();
}
?>
<html>
<body>
<form action = "<?php $_PHP_SELF ?>" method = "POST">
Name: <input type = "text" name = "name" />
Age: <input type = "text" name = "age" />
<input type = "submit" />
</form>
</body>
</html>
It will produce the following result −
Q.2 Attempt ANY TWO of the Following (800 Words)
Q.A Describe call by value and call by reference concept in PHP with example.
Answer :
Call by value method copies the value of an argument into the formal parameter of that
function. Therefore, changes made to the parameter of the main function do not affect the
argument.
In this parameter passing method, values of actual parameters are copied to function's
formal parameters, and the parameters are stored in different memory locations. So any
changes made inside functions are not reflected in actual parameters of the caller.
In Call by value method original value is not modified whereas, in Call by reference
method, the original value is modified.
In Call by value, a copy of the variable is passed whereas in Call by reference, a
variable itself is passed.
In Call by value, actual and formal arguments will be created in different memory
locations whereas in Call by reference, actual and formal arguments will be created
in the same memory location.
Call by value is the default method in programming languages like C++, PHP, Visual
Basic NET, and C# whereas Call by reference is supported only Java language.
Call by Value, variables are passed using a straightforward method whereas Call by
Reference, pointers are required to store the address of variables.
void main() {
int a = 10,
void increment(int);
Cout << "before function calling" << a;
increment(a);
Cout << "after function calling" << a;
getch();
void increment(int x) {
int x = x + 1;
Cout << "value is" << x;
}
Output:
Call by reference method copies the address of an argument into the formal parameter. In
this method, the address is used to access the actual argument used in the function call. It
means that changes made in the parameter alter the passing argument.In this method, the
memory allocation is the same as the actual parameters. All the operation in the function
are performed on the value stored at the address of the actual parameter, and the modified
value will be stored at the same address.
The function can change the value of the argument, which is quite useful.
It does not create duplicate data for holding only one value which helps you to save
memory space.
In this method, there is no copy of the argument made. Therefore it is processed
very fast.
Helps you to avoid changes done by mistake
A person reading the code never knows that the value can be modified in the
function.
Example of a Call by Reference method
Void increment(int x) {
int x = x + 1;
}
Output:
Answer :
A Data Type specifies a particular type of data, like integer, floating points, Boolean, etc. It
also identifies the possible values for that type, the operations that can be performed on
that type, and the way the values of that type are stored. In MySQL, each database table has
many columns and contains specific data typesfor each column. We can determine the data
type in MySQLwith the following characteristics:
o The type of values (fixed or variable) it represents.
o The storage space it takes is based on whether the values are a fixed-length or variable
length.
o Its values can be indexed or not.
o How MySQLperforms a comparison of values of a particular data type.
MySQLsupports a lot number of SQLstandard data types in various categories. It uses many
different data types that can be broken into the following categories: numeric, date and
time, string types, spatial types, and JSON data types
YEAR[(2|4)]
DATE
TIME
DATETIME
TIMESTAMP(m)
CHAR(size)
VARCHAR(size)
TINYTEXT(size)
TEXT(size)
MEDIUMTEXT(size)
LONGTEXT(size)
BINARY(size)
VARBINARY(size)
ENUM
SET
TINYBLOB
BLOB(size)
MEDIUMBLOB
LONGBLOB
GEOMETRY
POINT
POLYGON
LINESTRING
GEOMETRYCOLLECTION
MULTILINESTRING
MULTIPOINT
MULTIPOLYGON
Answer:
Arguments are specified after the function name, inside the parentheses. You can add as
many arguments as you want, just separate them with a comma.
The following example has a function with one argument ($fname). When the familyName()
function is called, we also pass along a name (e.g. Jani), and the name is used inside the
function, which outputs several different first names, but an equal last name:
<?php
function familyName($fname) {
echo "$fname Refsnes.<br>";
}
familyName("Jani");
familyName("Hege");
familyName("Stale");
familyName("Kai Jim");
familyName("Borge");
?>
OutPut
Jani Refsnes.
Hege Refsnes.
Stale Refsnes.
Kai Jim Refsnes.
Borge Refsnes.
Q3.
C . Cookie in PHP
Answer :
A cookie is a small file that the server embeds on the user's computer. Each time
the same computer requests a page with a browser, it will send the cookie too. With
PHP, you can both create and retrieve cookie values.
There are three steps involved in identifying returning users -
• Server script sends a set of cookies to the browser. For example name, age,
or identification number etc.
• Browser stores this information on local machine for future use.
• When next time browser sends any request to web server then it sends those
cookies information to the server and server uses that information to
identify the user
The following example creates a cookie named "user" with the value "John Doe".
The cookie will expire after 30 days (86400 * 30). The "/" means that the cookie is
available in entire website (otherwise, select the directory you prefer).
We then retrieve the value of the cookie "user" (using the global variable
$_COOKIE). We also use the isset() function to find out if the cookie is set:
setcookie() function
<?php
$cookie_name = "user";
$cookie_value = "Raj";
setcookie($cookie_name, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1
day
?>
<html>
<body>
<?php
if(!isset($_COOKIE[$cookie_name])) {
echo "Cookie named '" . $cookie_name . "' is not set!";
} else {
echo "Cookie '" . $cookie_name . "' is set!<br>";
echo "Value is: " . $_COOKIE[$cookie_name];
}
?>
</body>
</html>
The setcookie() function must appear BEFORE the <html> tag. The value of the
cookie is automatically URLencoded when sending the cookie, and automatically
decoded when received (to prevent URLencoding, use setrawcookie() instead).
Output:
Cookie 'user' is set!
Value is: Raj