WT UNIT 2
WT UNIT 2
PHP
Introduction to PHP: How PHP Works , The php.ini File, Basic PHP Syntax, PHP variables,
statements, operators, decision making, loops, arrays, strings, forms, get and post methods,
functions.
Introduction to cookies, storage of cookies at client side, Using information of cookies.
Creating single or multiple server side sessions. Timeout in sessions, Event management in
PHP.
Introduction to content management systems based on PHP.
PHP is a server-side scripting language. The client (web browser) sends a request to
the server for a PHP page. The server processes the PHP script, executes the code, and
sends the resulting output (usually HTML) back to the client. This makes PHP a
powerful tool for dynamic and interactive web pages.
Process:
Example:
<?php// This code runs on the serverecho "This is executed server-side and only the
output is visible to the client.";?>
php.iniis the main configuration file for PHP, where server behavior can be
customized. It dictates how PHP scripts execute and handles various settings related
to performance, security, and error handling.
Common Settings:
Security Note: Improper settings can expose sensitive information or make the server
vulnerable.
Example of Configuration:
; php.inidisplay_errors = Offmax_execution_time = 60upload_max_filesize = 5M
PHP scripts are enclosed within <?php ... ?> tags. PHP can be embedded in HTML,
making it easy to create dynamic web pages.
Rules:
Example:
<!DOCTYPE html>
<html>
<body>
<h1>Welcome Page</h1>
<?php
?>
</body>
</html>
4. PHP Variables
Variables in PHP are used to store data and start with a $ symbol. PHP is a loosely
typed language, so variable types are determined by their values.
Types of Variables:
Example:
Types of Operators:
Example:
6. Decision Making
PHP supports decision-making structures that help control the flow of code based on
conditions.
Types:
Example:
} else {
}?>
7. Loops
Loops in PHP allow you to execute the same block of code multiple times.
Types:
Example:
echo "$color<br>";
}?>
8. Arrays
Arrays store multiple values in a single variable and come in different forms.
Types:
Example:
<?php$students = array(
9. Strings
Strings in PHP are sequences of characters enclosed within single or double quotes.
PHP provides various string functions:
String Functions:
Example:
Forms collect user input and send data to the server using GET or POST.
GET:
POST:
$username = $_POST['username'];
}?>
11. Functions
Functions encapsulate reusable code blocks. PHP has built-in functions and allows
user-defined functions.
<?phpfunction greetUser($name) {
12. Cookies
Cookies store data on the client side to maintain user information across sessions.
Setting a Cookie:
Reading a Cookie:
<?phpif (isset($_COOKIE["username"])) {
}?>
13. Sessions
Sessions store data on the server and are more secure than cookies as they are not
stored on the client.
Starting a Session:
<?phpsession_start();$_SESSION["user"] = "JohnDoe";?>
Accessing a Session:
}?>
PHP-based CMS platforms like WordPress, Joomla, and Drupal simplify content
creation and website management without extensive coding knowledge.
Benefits:
User-friendly interfaces.
Extensibility through plugins and themes.
Community support and documentation.