Hypertext Preprocessor: Government College of Engineering, Yavatmal
Hypertext Preprocessor: Government College of Engineering, Yavatmal
A
SEMINAR
REPORT
ON
“PHP(Hypertext Preprocessor)”
PROF. R. DAHIWADE
CERTIFICATE
“PHP”
is a bonafide work and it is submitted to Government College of Engineering, Yavatmal
SUBMITTED BY:
The report has been approved as it satisfies the academic requirements in respect of
seminar work prescribed the course.
Dr.
V.B.Waghmare
(Principal)
Government College of Engineering, Yavatmal
DEPARTMENT OF COMPUTER
ENGINEERING GOVERNMENT COLLEGE OF
ENGINEERING, YAVATMAL
“PHP”
SUBMITTED BY:
ROLL NO.:37,38,39,40,41,42,43,44
PROF.
(Seminar Guide)
Department of Computer
Engineering Government College of
Engineering,
Yavatmal
ACKNOWLEDGEMENT
I would like to express our deepest appreciation to all those who provided us the
possibility to complete this seminar report. A special gratitude I give to our f i r s t year
seminar mentor, Prof. Shital Gawarle, whose contribution in stimulating suggestions and
encouragement helped us to coordinate our project. He gave us support from the start to the
end of this project and kept us on the correct path.
I would like to express my special thanks to Prof. Shital Gawarle, Seminar In-
Charge of Computer Engineering and Prof. Prof.C.V.Andhare, Head of the Department,
Computer Engineering, Government College of Engineering, Yavatmal who have
invested her full effort in guiding the team in achieving the goal for all the timely support and
valuable suggestions during the period of project.
I would like to express our sincere thanks to Dr. V.B.Waghmare, Principal
of Government College of Engineering Yavatmal, for providing the Working facilities
in college.
We are equally thankful to all the staff members of Computer Engineering
Department, Government College of Engineering, Yavatmal for their valuable suggestions.
Also, I would like to thank all of my friends for the continual encouragement and the
positive support.
Place: Yavatmal
Date:
TABLE OF CONTENTS
Topic 1 Introduction - 6 to 7
ABSTRACT
PHP (Hypertext Preprocessor) is a widely-used, open-source server-side scripting language designed
for web development. It is embedded into HTML code to create dynamic web pages and applications.
PHP enables developers to generate dynamic content, interact with databases, and manage session
states. As a versatile language, PHP supports various database systems, including MySQL and
PostgreSQL, and can run on multiple platforms such as Windows, Linux, and macOS. PHP has
become one of the core technologies for building interactive websites and web applications due to its
ease of integration with other technologies and frameworks.
The language's flexibility, vast community support, and rich library ecosystem make it a preferred
choice for developers creating content management systems, e-commerce platforms, and custom web
applications. PHP also features extensive security measures, though it requires best practices to
ensure secure coding and protect against vulnerabilities like SQL injection and cross-site scripting
(XSS). This abstract provides a brief overview of PHP's capabilities, its role in modern web
development, and its advantages in creating scalable and dynamic web solutions.
Topic 1: INTRODUCTION
PHP Introduction
PHP (Hypertext Preprocessor) is a general-purpose, high-level scripting language designed for web
development. Initially created by Rasmus Lerdorf in 1994, it is now maintained by the PHP Group.
PHP was specifically developed to enhance web applications' dynamic functionality, allowing
developers to create content-rich and interactive websites. PHP is renowned for its simplicity and the
ability to integrate seamlessly with databases and other technologies.
History of PHP
PHP was created in “1994” by Rasmus Lerdorf as "Personal Home Page Tools" to track website
visits.
In 1997, Zeev Suraski and Andi Gutmans revamped it, leading to PHP 3.0, renamed "PHP: Hypertext
Preprocessor." PHP 4.0, released in **2000, introduced the Zend Engine, boosting performance.
PHP 5.0 in “2004” added advanced object-oriented programming. PHP 7.0 in
” improved speed and memory usage, while PHP 8.0 in “2020” introduced the JIT compiler for better
performance. Today, PHP powers many websites, including WordPress and Wikipedia.
PHP Features
PHP is very popular language because of its simplicity and open source. There are some important
features of PHP given below
Performance:
PHP script is executed much faster than those scripts which are written in other languages such as JSP
and ASP. PHP uses its own memory, so the server workload and loading time is automatically
reduced, which results in faster processing speed and better performance.
Open Source:
PHP source code and software are freely available on the web. You can develop all the versions of
PHP according to your requirement without paying any cost. All its components are free to download
and use.
Familiarity with syntax:
PHP has easily understandable syntax. Programmers are comfortable coding with it.
Embedded:
PHP code can be easily embedded within HTML tags and script.
Platform Independent:
PHP is available for WINDOWS, MAC, LINUX & UNIX operating system. A PHP application
developed in one OS can be easily executed in other OS also.
Database Support:
PHP supports all the leading databases such as MySQL, SQLite, ODBC, etc.
Error Reporting –
PHP has predefined error reporting constants to generate an error notice or warning at runtime. E.g.,
E_ERROR, E_WARNING, E_STRICT, E_PARSE.
Loosely Typed Language:
PHP allows us to use a variable without declaring its datatype. It will be taken automatically at the
time of execution based on the type of data it contains on its value.
Web servers Support:
PHP is compatible with almost all local servers used today like Apache, Netscape, Microsoft IIS, etc.
Security:
PHP is a secure language to develop the website. It consists of multiple layers of security to prevent
threads and malicious attacks
Control:
Different programming languages require long script or code, whereas PHP can do the same work in
a few lines of code. It has maximum control over the websites like you can make changes easily
whenever you want.
Computer Department GCOEY 2024-2025
PHP(Hypertext Preprocessor)
PHP, a powerful server-side scripting language used in web development. It’s simplicity and
ease of use makes it an ideal choice for beginners and experienced developers. This article
provides an overview of PHP syntax. PHP scripts can be written anywhere in the document
within PHP tags along with normal HTML.
<?php
// code
?>
The script starts with <?php and ends with ?>. These tags are also called ‘Canonical PHP tags’.
Everything outside of a pair of opening and closing tags is ignored by the PHP parser. The open
and closing tags are called delimiters. Every PHP command ends with a semi-colon (;).
?>
PHP Variables:
A variable in PHP is the name of the memory location that holds data. In PHP, a variable is
declared using the $ sign followed by the variable name.
PHP Variable Scope
The scope of a variable refers to where it can be accessed within the
code. PHP variables can have local, global, static, or superglobal scope
.
1. Local Scope or Local Variable
Variables declared within a function have local scope and cannot be accessed outside the
function. Any declaration of a variable outside the function with the same name (as within the
function) is a completely different variable.
Example: This example shows the local variable in PHP. PHP
php
$num = 60;
function local_var() {
local_var();
Output
The variables declared outside a function are called global variables. These
variables can be accessed directly outside a function. To get access within
a function we need to use the “global” keyword before the variable to refer to the global variable.
Example: This example shows the Global Variables in PHP.
PHP
php
$num = 20;
global_var();
Output
Variable num inside function: 20 Variable
num outside function: 20
3. Static Variables
It is the characteristic of PHP to delete the variable. Once it completes its execution and the
memory is freed. But sometimes we need to store the variables even after the completion of
function execution. To do this, we use the static keywords and the variables are then called static
variables. PHP associates a data type depending on the value for the variable.
Example: This example shows the Static variable in PHP.
PHP
php
// Static Variable
static $num = 5;
$sum = 2;
$sum++;
$num++;
Output
6
3
7
3
4. Superglobals
Superglobals are built-in arrays in PHP that are accessible from anywhere in the script,
including within functions. Common superglobals include $_GET, $_POST,
$_SESSION, $_COOKIE, $_SERVER, and $_GLOBALS.
PHP
php
Variable
•PHP allows us to use dynamic variable names, called variable variables.
•Variable variables are simply variables whose names are dynamically created by
another variable’s value.
Example: This example shows the declaration of a variable by the use of the another variable.
PHP
php
$a = 'hello'; //hello is value of variable $a
$$a = 'World'; //$($a) is equals to $(hello)
echo $hello; //$hello is World i.e. $hello is new variable with value 'World'
PHP Constant:
In PHP, constants are variables that have a fixed value and cannot be changed during the
execution of a program.
Example
Create a case-sensitive constant with the const keyword:
const MYCAR = "Volvo";
echo MYCAR;
PHP Constant Arrays
From PHP7, you can create an Array constant using the define() function.
Example
Create an Array constant:
define("cars", [
"Alfa Romeo",
"BMW",
"Toyota"
]);
echo cars[0]; Constants
are Global
Constants are automatically global and can be used across the entire script.
Example
This example uses a constant inside a function, even if it is defined outside the function:
define("GREETING", "Welcome to W3Schools.com!");
function myTest() {
echo GREETING; }
myTest();
A. String
Integer
Can be in decimal (base 10), hexadecimal (base 16), octal (base 8), or binary (base 2).
Example:
$decimal = 42;
B. Float
Example:
$pi = 3.14159;
• Example:
Indexed Array:
Associative Array:
• Example:
Class Car {
Public $brand;
$this->brand = $brand;
$car->setBrand(“Toyota”);
$var = NULL;
Resource
• Example:
a. Gettype()
$var = “Hello”;
a. Var_dump()
a. Is_*() Functions
• Is_int()
• Is_string()
• Is_array()
• Is_null()
• Is_bool()
• Example:
$var = 3.14;
If (is_float($var)) {
Type Casting
• Example:
$var = “10”;
PHP is dynamically typed, meaning variables do not have fixed types. The type is determined
by the value assigned.
• Example:
What is operators?
Operators are used to performing operations on some values. In other words, we can describe
operators as something that takes some values, performs some operation on them, and gives a
result.
1.ARITHMETIC OPERATORS
In PHP, arithmetic operators are used to perform mathematical operations on numeric
values.
OPERATOR NAME EXAMPLE OPERATION
+ Addition $x + $y Sum the product
- Subtraction $x - $y Differences the operands
* Multiplication $x * $y Product of the operands
/ Division $x / $y The quotient of the operand
** Exponentiation $x ** $y $x raised to the power $y
Modulus $x % $y The remainder of the operands
%
2.COMPARISON OPERATORS
Comparison operators are used to compare two values in a Boolean fashion.
<= Less than or $x <= $y Checks if the left operand is less than
equal to or equal to the right.
3.LOGICAL OPERATORS
They are basically used to operate with conditional statements and expressions.
Conditional statements are based on conditions
4.ARRAY OPERATORS
These operators are used in the case of arrays
5.STRING OPERATORS
This operator is used for the concatenation of 2 or more strings using the concatenation operator
(‘.’). We can also use the concatenating assignment operator (‘.=’) to append the argument on the
right side to the argument on the left side.
6.BITWISE OPERATORS
The bitwise operators are used to perform bit-level operations on operands. These operators allow the
evaluation and manipulation of specific bits within the integer.
• A regular expression is a sequence of characters that forms a search pattern. When you
search for data in a text, you can use this search pattern to describe what you are
searching for.
• A regular expression can be a single character, or a more complicated pattern.
• Regular expressions can be used to perform all types of text search and text replace
operations.
SYNTAX
$exp = "/helloworld/i";
Function Description
preg_match() Returns 1 if the pattern was found in the string and 0 if not
preg_match_all() Returns the number of times the pattern was found in the string, which may
also be 0
preg_replace()
Returns a new string where matched patterns have been replaced with
another string
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0”>
<title>Form Example</title>
</head>
<body>
<form action=”capture_form_data.php” method=”post”>
<label for=”username”>Username:</label>
<input type=”text” id=”username” name=”username” required><br><br>
<label for=”email”>Email:</label>
<input type=”email” id=”email” name=”email” required><br><br>
<label for=”password”>Password:</label>
<input type=”password” id=”password” name=”password” required><br><br>
<button type=”submit”>Register</button>
</form>
</body>
</html>
<?php
// Check if the form was submitted
If ($_SERVER[“REQUEST_METHOD”] === “POST”) {
// Capture form data
$username = $_POST[‘username’];
$email = $_POST[‘email’];
$password = $_POST[‘password’];
1. HTTP Methods:
GET: Appends data to the URL (less secure and limited in size).
1. Global Variables:
1. Example: Using GET Method: Modify the form to use method=”get”, and access data via
$_GET:
$username = $_GET[‘username’];
$email = $_GET[‘email’];
Validation
If (empty($username)) {
Die(“Username is required.”);
}
If (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
Die(“Invalid email address.”);
}
2.Sanitization
Sanitize data to remove unwanted characters.
1. Use Prepared Statements: When storing data in a database, use prepared statements
to prevent SQL injection.
2. Input Length Limits: Enforce length limits in both the form and server-side validation.
5. CSRF Protection: Add a CSRF token to the form to prevent Cross-Site Request
Forgery attacks.
Capturing HTML form data using PHP is a straightforward process, but ensuring data validity
and security is critical. By combining proper input validation, sanitization, and secure coding
practices, developers can build robust web applications that safely handle user input.
This foundational knowledge can be extended to advanced use cases like file uploads, session
handling, and AJAX-based forms.
Redirecting a user after form submission is a common practice in web development. It ensures
better user experience by preventing duplicate submissions caused by browser refreshes and
allows the developer to guide users to specific pages, such as a thank-you page or a confirmation
screen.
Implementation in PHP
PHP provides several methods to redirect users. The most common way is using the header()
function.
If ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
// Process the form data
$name = $_POST[‘name’];
$email = $_POST[‘email’];
If ($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
// Process the form data
$success = true;
In this example, a success message can be displayed on the redirected page based on the query
parameter.
If validation fails, redirect the user back to the form with error messages. If
($_SERVER[‘REQUEST_METHOD’] == ‘POST’) {
$errors = [];
// Validate input
If (empty($_POST[‘name’])) {
$errors[] = ‘Name is required’;
}
If (!empty($errors)) {
// Redirect back to the form with errors
$query = http_build_query([‘errors’ => $errors]);
Header(‘Location: form.php?’ . $query);
Exit;
}
Note: Error messages can be retrieved using $_GET[‘errors’] on the form page.
3. Security Concerns:
Always sanitize input to prevent security risks like XSS or SQL injection. Use HTTPS
4. JavaScript Redirects:
<script>
Window.location.href = ‘thank_you.php’;
</script>
However, these rely on client-side scripts and are not ideal for critical redirects.
Redirecting users after form submission in PHP ensures a smooth user experience and protects
against duplicate submissions. By leveraging the header() function and properly handling
validation and errors, developers can build robust and user- friendly web applications.
PHP sessions are a way to store data across multiple pages during a user's visit to a
website. Sessions allow you to maintain state and store user-specific information, such as
login credentials, preferences, or shopping cart contents, without relying on cookies or
URL parameters.
6. Destroying a Session
To completely destroy a session and remove all session data, use the
session_destroy() function. This is usually done when a user logs out.
CONCLUSION
In summary, we have covered the essential aspects of PHP that form the backbone of
dynamic web development. We started with an introduction to PHP, then explored its
basic syntax, variables, and constants, which are fundamental for data manipulation. We
examined various data types and the use of operators and expressions for performing
operations on data.
We also learned how to handle HTML forms in PHP, capturing user input and managing
multi-value fields effectively. Redirecting users after form submission enhances user
experience, and PHP sessions allow us to maintain user state across different pages.
By understanding these core concepts, you are equipped to build dynamic and interactive
web applications. As you progress, delving into more advanced topics will further
enhance your PHP skills and enable you to create sophisticated web solutions.
REFERENCE
1. www.google.com
2. https://www.w3schools.com/php/default.asp
3. www.chatgpt.com
4. https://www.php.net/
5. https://www.geeksforgeeks.org/php
6. https://www.w3schools.com/PHP
7. https://www.javatpoint.com
8. https://blog.hubspot.com/website/php-array-functions
9. https://corporatefinanceinstitute.com/resources/data-science/.
10. https://www.tutorialspoint.com/php/index.htm