Q2 and notes php
Q2 and notes php
and variable ?
Constant Variable:
A constant A variable
is a name or is a name for
an identifier a storage
for a simple location that
value. holds data
that can be
changed
during script
execution.
The value Variables
cannot be are declared
changed using the
during the dollar sign ($)
script followed by
execution. the variable
name.
Constants Variables
are defined can have
using the their values
define() changed at
function or any time.
the const
keyword.
Constants Variables
do not are local to
require a the scope in
dollar sign ($) which they
before their are defined,
name. unless
declared
global.
methods to
submit form.
GET Method: Data is sent appended to the
URL as query strings. It is visible to
everyone and has length limitations.
POST Method: Data is sent in the request
body. It is not visible in the URL and has no
size limitations.P
e)what is a session in PHP? Explain it.
A session in PHP is a way to store
information (in variables) to be used across
multiple pages. Unlike a cookie, the
information is not stored on the user's
computer.
Starting a Session:
php
session_start();
Setting Session Variables:
php
$_SESSION["username"] = "John";
Accessing Session Variables:
php
echo $_SESSION["username"];
Ending a Session:
php
session_unset(); // remove all session
variables
session_destroy(); // destroy the session
a) What are the different types of PHP
variables?
POST:
Data is sent via the request body.
Larger amounts of data can be sent.
Data is not visible in the URL, making it
more secure.
Cannot be bookmarked or cached.
c) Explain if ...... then else in PHP.
In PHP, the if...then...else statement is used
for conditional execution of code blocks.
Here's a breakdown of its structure and
functionality:
Explanation
1. Condition: This is an expression that evaluates to either
true or false. It can be any expression that PHP can
evaluate to a boolean value.
2. Code Block for if: If the condition evaluates to true,
the code inside the first block (following if) will be
executed.
3. Code Block for else: If the condition evaluates to
false, the code inside the else block will be executed
instead.
d) Explain cookies in PHP
Cookies are small files that the server
embeds on the user's computer.
They are used to store data about the
user for tracking and personalization
purposes.
e) Explain any two string functions in PHP.