Dynamic Web Application Development with PHP: Complete Study Notes

Fundamental Concepts of Web Development

Open Source vs. Freeware

When evaluating web application software and development tools, software distribution models determine code accessibility and user rights:

  • Freeware: Software that is available for use at zero monetary cost. However, users are strictly prohibited from accessing, viewing, or modifying the underlying source code.

  • Open Source: Software that grants users the freedom to view, inspect, modify, and redistribute its source code. Open-source projects encourage community collaboration, allowing developers worldwide to submit modifications, bug fixes, and feature enhancements.

Static vs. Dynamic Web Sites

Websites are categorized based on how their content is processed and served to clients:

  • Static Web Pages: Display fixed content that remains identical for all users. The web server stores pre-written files (such as HTML, CSS, and static images) and delivers them directly to the client browser without executing any server-side processing.

  • Dynamic Web Pages: Construct content on the fly at the time of a user request. They utilize server-side processing scripts and database engines to deliver interactive, personalized experiences that adapt based on user input, context, or session state.


Main differences between a static vs dynamic website
Comparative Overview
  • Content Variability: Content on static websites is stable and unchanging. Dynamic site content changes dynamically based on behavioral rules and targeted user profiles.

  • Storage & Delivery: Static content is pulled directly as flat files from the server filesystem. Dynamic content resides in database engines or data collections and is queried, filtered, and rendered dynamically.

  • Maintenance Effort: Modifying a static website requires editing HTML files page by page. Updates on dynamic websites can be applied across thousands of pages automatically through template or database updates.

  • User Interactivity: Static sites offer passive viewing experiences with minimal user input functionality. Dynamic sites support robust user input, form submissions, and interactive data manipulation.

  • Development Trade-offs: Dynamic websites require higher initial setup time and technical complexity, but prove vastly more efficient to manage long term. Static websites are quick to deploy initially, but require labor-intensive content management as the site scales.

Introduction to PHP

Definition and Acronym Evolution

PHP is a widely-used, open-source general-purpose scripting language specifically designed for server-side web development. PHP scripts execute on the web server before the resulting output is sent to the client browser.

  • Original Name: Created in 1995, the acronym originally stood for Personal Home Pages.

  • Modern Acronym: PHP is currently a recursive acronym standing for PHP: Hypertext Preprocessor.

Historical Timeline and Version History

  • June 8, 1995: Rasmus Lerdorf posted PHP 1.0 (originally named "PHP Tools") to the Usenet newsgroup comp.infosystems.www.authoring.cgi.

  • April 1996: Rasmus integrated his tools with the Apache web server, introducing PHP/FI (Forms Interpreter) 2.0. This release added built-in support for DBM, mSQL, and Postgres95 databases, HTTP cookies, and user-defined functions.

  • PHP 3.0: Zeev Suraski and Andi Gutmans rewrote the core parser from scratch, establishing the official acronym PHP: Hypertext Preprocessor. PHP 3.0 provided a mature interface for multiple databases, unified syntax, and initial Object-Oriented Programming (OOP) constructs.

  • May 2000 (PHP 4.0): Powered by the newly designed Zend Engine. Introduced native HTTP session management, output buffering, multi-web-server support, and enhanced security primitives for user input handling.

  • July 2004 (PHP 5.0): Driven by Zend Engine 2.0, featuring an overhauled object-oriented model and numerous language enhancements.

  • December 2015 (PHP 7.0): Derived from the development branch known as "phpng" (PHP Next Generation) and powered by Zend Engine 3. Delivered major execution speed improvements over PHP 5.6, strict type declarations for function arguments, enhanced error handling, and new operators.

  • November 26, 2020 (PHP 8.0): Introduced Just-In-Time (JIT) compilation to provide substantial execution speed gains.

  • July 4, 2023 (PHP 8.2.8): Maintenance release within the PHP 8 release series.

Key Capabilities of PHP

  • Generates dynamic webpage content on demand.

  • Executes server filesystem operations: creating, opening, reading, writing, deleting, and closing files.

  • Collects data submitted through HTTP web forms.

  • Sends, receives, and manages HTTP cookies.

  • Performs database CRUD operations (Create, Read, Update, Delete).

  • Controls user access rights and handles session authentication.

  • Encrypts sensitive data.

Advantages of PHP

  • Cross-Platform Integration: Runs natively on Windows, Linux, Unix, macOS, and other major operating systems.

  • Server Compatibility: Integrates seamlessly with almost all modern web servers, including Apache and IIS.

  • Database Integration: Supports native drivers for a wide range of relational and non-relational databases.

  • Cost: Free to download and distribute from official repositories at www.php.net.

  • Efficiency & Learning Curve: Straightforward syntax with fast server-side execution performance.

PHP File Structure

  • File Extension: PHP script files must save with the .php file extension.

  • File Contents: A .php file contains plain text, HTML markup, CSS styling, JavaScript code, and embedded PHP code blocks.

  • Processing: When a client requests a .php file, the server processes the PHP code blocks and returns clean, rendered plain HTML to the client browser.

Environment Setup via XAMPP

To execute PHP scripts locally, developers utilize stack distributions like XAMPP (Apache, MySQL, PHP, and phpMyAdmin).

  1. Download Installer:

    • Visit https://www.apachefriends.org/.

    • Select the installer matching the operating system (Windows, macOS, or Linux) and architecture (32-bit or 64-bit).

  2. Execute Installation:

    • Launch the .exe setup file and accept User Account Control (UAC) prompts.

    • Step through the Setup Wizard: Welcome Screen -> Select Components (default components: Apache, MySQL, PHP, phpMyAdmin) -> Specify Installation Folder (default: C:\xampp) -> Set Start Menu Folder -> Click Install -> Complete setup by clicking Finish.

PHP Syntax and Execution Architecture

Client-Server Execution Flow

  1. Page Request: The client browser sends an HTTP request for a .php file to the web server.

  2. Code Routing: The web server detects the .php extension and routes the PHP code to the internal PHP Parser.

  3. Script Execution: The PHP Parser executes the embedded script logic and generates a plain HTML payload.

  4. Response Delivery: The PHP Parser returns the HTML to the web server, which sends the rendered HTML back to the client browser.


PHP Execution Architecture Diagram

Tag Syntax and Placement

PHP code blocks are delimited by canonical PHP tags:

<?php
    // One or more PHP statements
?>

PHP blocks can be inserted anywhere within an HTML document structure:

<!DOCTYPE html>
<html>
<body>
    <h1>My PHP Website</h1>
    <?php
        echo "Hello World!";
    ?>
</body>
</html>

Statements and Semicolons

  • PHP code consists of a sequence of statements.

  • Every individual PHP statement MUST end with a terminating semicolon ;.

<?php
    echo "<h1 align='center'>Hello World!</h1>";
?>

Case Sensitivity Rules

  • Case-Insensitive Primitives: Core language keywords (if, else, while, echo, etc.), class names, built-in functions, and user-defined functions are case-insensitive. The statements ECHO, echo, and EcHo operate identically.

  • Case-Sensitive Variables: All variable names ARE strictly case-sensitive. Declaring $color does not define $COLOR or $coLOR.

<!DOCTYPE html>
<html>
<body>
<?php
    $color = "red";
    echo "My car is " . $color . "<br>";  // Outputs "red"
    echo "My house is " . $COLOR . "<br>"; // Triggers an undefined variable error
    echo "My boat is " . $coLOR . "<br>";  // Triggers an undefined variable error
?>
</body>
</html>

Comments in PHP

Comments are non-executing text lines used for developer documentation, code clarification, or temporarily disabling script segments.

// This is a single-line comment

# This is also a single-line comment

/* This is a 
multi-line comment */

Variables in PHP

Core Variable Principles

Variables serve as containers for storing data types such as text strings, integers, floats, and arrays.

  • No Explicit Declaration: Variables do not require explicit type declaration before assignment.

  • Implicit Data Typing: PHP automatically assigns and converts variable data types depending on the assigned value.

  • Scope & Reusability: Once defined, a variable can be reassigned and accessed throughout its executable scope.

  • Assignment Operator: Values are bound to variables using the assignment operator =.

Syntax and Declaration

Declaring a variable follows the construct $variable_name = value;.

<?php
    $stud_name = "Dina Lee Go";
    $age = 21;
    echo "Name: $stud_name <br>";
    echo "Age: $age";
?>

Variable Naming Conventions

  1. A variable name MUST always begin with a dollar sign $.

  2. The character immediately following the $ MUST be a letter (a-z, A-Z) or an underscore _.

  3. A variable name CANNOT begin with a number.

  4. Variable names can ONLY contain alphanumeric characters and underscores (A-z, 0-9, and _).

  5. Spaces are strictly forbidden within variable names.

  6. Variable names are strictly case-sensitive ($x and $X are two separate variables).

Output Statements: Echo and Print

PHP provides two basic constructs to output data to the output stream: echo and print.

Functional Comparison

Feature

echo Statement

print Statement

Return Value

No return value

Always returns an integer value of 1

Expression Usage

Cannot be used inside expressions

Can be used inside complex expressions

Parameters

Accepts multiple comma-separated arguments

Accepts only a single argument

Syntax

echo or echo(...)

print or print(...)

Performance

Marginally faster execution

Marginally slower due to return value

Code Implementation Examples

Outputting Text Strings
<?php
    // Displaying a simple text string
    print "Hello, World!";
?>
Outputting Formatted HTML
<?php
    // Displaying raw HTML elements and inline CSS
    print "<h4>This is a simple heading.</h4>";
    print "<h4 style='color: red;'>This is heading with style.</h4>";
?>
Displaying Variables and Array Elements
<?php
    // Defining variables
    $txt = "Hello World!";
    $num = 123456789;
    $colors = array("Red", "Green", "Blue");

    // Displaying variables
    echo $txt;
    echo "<br>";
    echo $num;
    echo "<br>";
    echo $colors[0];
?>

PHP Operators

Operators represent operations performed on variables and values.

Arithmetic Operators

Arithmetic operators process numeric values to evaluate fundamental mathematical calculations.

Operator

Name

Example

Result Description

+

Addition

$x1 + $x2

Sum of $x1 and $x2

-

Subtraction

$x1 - $x2

Difference of $x1 and $x2

*

Multiplication

$x1 * $x2

Product of $x1 and $x2

/

Division

$x1 / $x2

Quotient of $x1 and $x2

%

Modulus

$x1 % $x2

Remainder of $x1 divided by $x2

**

Exponentiation

$x1 ** $x2

Result of raising $x1 to the $x2'th power

Assignment Operators

Assignment operators evaluate expressions and store the result into the left operand.

Assignment

Equivalent To

Description

x1 = x2

x1 = x2

Sets the left operand to the value of the expression on the right

x1 += x2

x1 = x1 + x2

Addition assignment

x1 -= x2

x1 = x1 - x2

Subtraction assignment

x1 *= x2

x1 = x1 * x2

Multiplication assignment

x1 /= x2

x1 = x1 / x2

Division assignment

x1 %= x2

x1 = x1 % x2

Modulus assignment

Comparison Operators

Comparison operators compare two scalar values (numbers or text strings) and return a boolean true or false.

Operator

Name

Example

Result Condition

==

Equal

$x == $y

Returns true if $x is equal to $y

===

Identical

$x === $y

Returns true if $x is equal to $y, and they are of the same type

!=

Not equal

$x != $y

Returns true if $x is not equal to $y

<>

Not equal

$x <> $y

Returns true if $x is not equal to $y

!==

Not identical

$x !== $y

Returns true if $x is not equal to $y, or they are of different types

>

Greater than

$x > $y

Returns true if $x is strictly greater than $y

<

Less than

$x < $y

Returns true if $x is strictly less than $y

>=

Greater than or equal to

$x >= $y

Returns true if $x is greater than or equal to $y

<=

Less than or equal to

$x <= $y

Returns true if $x is less than or equal to $y

<=>

Spaceship

$x <=> $y

Returns an integer less than, equal to, or greater than zero (1,0,1-1, 0, 1) if $x is less than, equal to, or greater than $y (introduced in PHP 7)

Increment / Decrement Operators

Increment and decrement operators modify variable integer or float values by one.

Operator

Name

Description

++$x

Pre-increment

Increments $x by one, then returns $x

$x++

Post-increment

Returns $x, then increments $x by one

--$x

Pre-decrement

Decrements $x by one, then returns $x

$x--

Post-decrement

Returns $x, then decrements $x by one

Logical Operators

Logical operators evaluate combined conditional expressions.

Operator

Name

Example

Result Condition

and

And

$x and $y

True if both $x and $y evaluate to true

or

Or

$x or $y

True if either $x or $y evaluates to true

xor

Xor

$x xor $y

True if either $x or $y is true, but not both

&&

And

$x && $y

True if both $x and $y evaluate to true

||

Or

$x || $y

True if either $x or $y evaluates to true

!

Not

!$x

True if $x is not true

String Operators

PHP provides two operators specially designed for handling text strings.

Operator

Name

Example

Result Description

.

Concatenation

$txt1 . $txt2

Concatenates $txt1 and $txt2 into a single string

.=

Concatenation assignment

$txt1 .= $txt2

Appends the string $txt2 onto $txt1

Array Operators

Array operators compare and merge PHP arrays.

Operator

Name

Example

Result Condition

+

Union

$x + $y

Union of array $x and array $y

==

Equality

$x == $y

Returns true if $x and $y contain identical key/value pairs

===

Identity

$x === $y

Returns true if $x and $y contain identical key/value pairs in the same order and of the same types

!=

Inequality

$x != $y

Returns true if $x is not equal to $y

<>

Inequality

$x <> $y

Returns true if $x is not equal to $y

!==

Non-identity

$x !== $y

Returns true if $x is not identical to $y

Conditional Assignment Operators

Conditional assignment operators set variable values based on conditional checks.

Operator

Name

Example

Result Condition

?:

Ternary

$x = expr1 ? expr2 : expr3

Value of $x is set to expr2 if expr1 = TRUE. Value of $x is set to expr3 if expr1 = FALSE

??

Null coalescing

$x = expr1 ?? expr2

Value of $x is set to expr1 if expr1 exists and is not NULL. If expr1 does not exist or is NULL, value of $x is set to expr2 (introduced in PHP 7)

Data Collection via HTTP Forms

Web Forms Architecture

An HTML web form provides a document containing user input controls (GUI elements such as text fields, radio buttons, checkboxes, dropdowns, and submit buttons) that allow users to enter or select data. Forms transmit collected user inputs to a web server for processing, session handling, or database storage.

The HTTP Protocol

Communication between client web browsers and web servers occurs via the Hypertext Transfer Protocol (HTTP), a request-response protocol:

  1. HTTP Request: The client browser submits a request message to the web server.

  2. HTTP Response: The web server processes the request and responds with status metadata and payload content.

HTTP GET Method

The GET method requests data from a specified resource by appending payload parameter key/value pairs directly into the URL query string.

Characteristics of GET Requests
  • Parameters are appended directly to the URL string (e.g., getmethod.php?username=John&city=NewYork).

  • GET requests can be cached by browsers.

  • GET requests remain stored in browser history.

  • GET requests can be saved as browser bookmarks.

  • GET requests have strict data length limits due to URL length restrictions.

  • GET requests only permit ASCII character encodings.

  • GET requests are intended exclusively for requesting data (read-only operations), not modifying server state.

  • Security Risk: GET requests expose data in the browser address bar and must NEVER be used when transmitting sensitive information such as passwords or tokens.

GET Method Implementation Example

index.html File:

<!DOCTYPE html>
<html>
<body>
    <form action="getmethod.php" method="GET">
        Username: <input type="text" name="username" /><br>
        City: <input type="text" name="city" /><br>
        <input type="submit" />
    </form>
</body>
</html>

getmethod.php File:

<!DOCTYPE html>
<html>
<body>
    Welcome <?php echo $_GET["username"]; ?><br>
    Your City is: <?php echo $_GET["city"]; ?>
</body>
</html>

HTTP POST Method

The POST method transmits user payload data encapsulated within the message body of the HTTP request.

Request Header Format
POST /test/demo_form.php HTTP/1.1
Host: w3schools.com

name1=value1&name2=value2
Characteristics of POST Requests
  • Data payload is stored within the request body rather than appended to the URL.

  • POST requests are never cached by browsers.

  • POST requests do not remain in browser history.

  • POST requests cannot be bookmarked.

  • POST requests have no payload length restrictions.

  • POST requests allow all data types, including binary data and multipart file uploads.

  • POST requests are used to create or modify data on the server.

  • Enhanced Security: Data parameters are not exposed in the URL address bar.

POST Method Implementation Example

index.html File:

<!DOCTYPE html>
<html>
<body>
    <form action="postmethod.php" method="post">
        Username: <input type="text" name="username" /><br>
        Area of Study: <input type="text" name="area" /><br>
        <input type="submit" />
    </form>
</body>
</html>

postmethod.php File:

<!DOCTYPE html>
<html>
<body>
    Welcome <?php echo $_POST["username"]; ?><br>
    Your Area of Study is: <?php echo $_POST["area"]; ?>
</body>
</html>

Exhaustive Comparison: HTTP GET vs. HTTP POST

Characteristic

HTTP GET

HTTP POST

Data Attachment

Request parameters appended into URL

Request parameters appended into request message body

Data Volume Limit

Limited data capacity (restricted character length)

Large/unlimited data volume supported

Usage Frequency

Used more frequently due to lightweight read operations

Used less frequently relative to simple data queries

Resource Action

Used exclusively to request/read data

Used to create, modify, or update server data

Address Bar Visibility

Data is fully visible in browser URL bar

Data is hidden from address bar

Browser History

Requests are stored in browser history

Requests are not stored in browser history

Bookmark Support

Requests can be saved as bookmarks

Requests cannot be saved as bookmarks

Browser Caching

Cached in browser cache memory

Not stored in browser cache memory

Security & Vulnerability

Less secure; data easily intercepted/stolen via URL

Comparatively more secure; URL data is hidden

Data Character Sets

ASCII characters allowed exclusively

All data types and binary formats allowed

Server Processing Workflow

Form submission, state evaluation, and session handling follow a structured workflow:

  1. Form Input: The user inputs credentials (such as a password) into client GUI form fields.

  2. Form Submission: The user submits the form via the POST method.

  3. Server Evaluation: The server receives the POST body, executes backend logic, and verifies the credentials against the database.

  4. 303 Redirect Response: Upon successful verification, the server issues a 303 HTTP response, embeds session cookies into response headers, and terminates the script.

  5. Application Access: The browser receives the redirect command, reloads the client context (index.php), and grants the user secure access to the web application.


Methods of sending information to server diagram


Open Source vs. Freeware

When evaluating web application software and development tools, software distribution models determine code accessibility and user rights:

  • Freeware: Software that is available for use at zero monetary cost. However, users are strictly prohibited from accessing, viewing, or modifying the underlying source code.

  • Open Source: Software that grants users the freedom to view, inspect, modify, and redistribute its source code. Open-source projects encourage community collaboration, allowing developers worldwide to submit modifications, bug fixes, and feature enhancements.

Static vs. Dynamic Web Sites

Websites are categorized based on how their content is processed and served to clients:

  • Static Web Pages: Display fixed content that remains identical for all users. The web server stores pre-written files (such as HTML, CSS, and static images) and delivers them directly to the client browser without executing any server-side processing.

  • Dynamic Web Pages: Construct content on the fly at the time of a user request. They utilize server-side processing scripts and database engines to deliver interactive, personalized experiences that adapt based on user input, context, or session state.

Definition and Acronym Evolution

PHP is a widely-used, open-source general-purpose scripting language specifically designed for server-side web development. PHP scripts execute on the web server before the resulting output is sent to the client browser.

  • Original Name: Created in 1995, the acronym originally stood for Personal Home Pages.

  • Modern Acronym: PHP is currently a recursive acronym standing for PHP: Hypertext Preprocessor.

Historical Timeline and Version History
  • June 8, 1995: Rasmus Lerdorf posted PHP 1.0 (originally named PHP Tools) to the Usenet newsgroup comp.infosystems.www.authoring.cgi.

  • April 1996: Rasmus integrated his tools with the Apache web server, introducing PHP/FI (Forms Interpreter) 2.0. This release added built-in support for DBM, mSQL, and Postgres95 databases, HTTP cookies, and user-defined functions.

  • PHP 3.0: Zeev Suraski and Andi Gutmans rewrote the core parser from scratch, establishing the official acronym PHP: Hypertext Preprocessor. PHP 3.0 provided a mature interface for multiple databases, unified syntax, and initial Object-Oriented Programming (OOP) constructs.

  • May 2000 (PHP 4.0): Powered by the newly designed Zend Engine. Introduced native HTTP session management, output buffering, multi-web-server support, and enhanced security primitives for user input handling.

  • July 2004 (PHP 5.0): Driven by Zend Engine 2.0, featuring an overhauled object-oriented model and numerous language enhancements.

  • December 2015 (PHP 7.0): Derived from the development branch known as phpng (PHP Next Generation) and powered by Zend Engine 3. Delivered major execution speed improvements over PHP 5.6, strict type declarations for function arguments, enhanced error handling, and new operators.

  • November 26, 2020 (PHP 8.0): Introduced Just-In-Time (JIT) compilation to provide substantial execution speed gains.

  • July 4, 2023 (PHP 8.2.8): Maintenance release within the PHP 8 release series.

Key Capabilities of PHP
  • Generates dynamic webpage content on demand.

  • Executes server filesystem operations: creating, opening, reading, writing, deleting, and closing files.

  • Collects data submitted through HTTP web forms.

  • Sends, receives, and manages HTTP cookies.

  • Performs database CRUD operations (Create, Read, Update, Delete).

  • Controls user access rights and handles session authentication.

  • Encrypts sensitive data.

Advantages of PHP
  • Cross-Platform Integration: Runs natively on Windows, Linux, Unix, macOS, and other major operating systems.

  • Server Compatibility: Integrates seamlessly with almost all modern web servers, including Apache and IIS.

  • Database Integration: Supports native drivers for a wide range of relational and non-relational databases.

  • Cost: Free to download and distribute from official repositories at www.php.net.

  • Efficiency & Learning Curve: Straightforward syntax with fast server-side execution performance.

PHP File Structure
  • File Extension: PHP script files must save with the .php file extension.

  • File Contents: A .php file contains plain text, HTML markup, CSS styling, JavaScript code, and embedded PHP code blocks.

  • Processing: When a client requests a .php file, the server processes the PHP code blocks and returns clean, rendered plain HTML to the client browser.

Environment Setup via XAMPP

To execute PHP scripts locally, developers utilize stack distributions like XAMPP (Apache, MySQL, PHP, and phpMyAdmin).

  1. Download Installer:

    • Visit https://www.apachefriends.org/.

    • Select the installer matching the operating system (Windows, macOS, or Linux) and architecture (32-bit or 64-bit).

  2. Execute Installation:

    • Launch the .exe setup file and accept User Account Control (UAC) prompts.

    • Step through the Setup Wizard: Welcome Screen -> Select Components (default components: Apache, MySQL, PHP, phpMyAdmin) -> Specify Installation Folder (default: C:\xampp) -> Set Start Menu Folder -> Click Install -> Complete setup by clicking Finish.

Client-Server Execution Flow
  1. Page Request: The client browser sends an HTTP request for a .php file to the web server.

  2. Code Routing: The web server detects the .php extension and routes the PHP code to the internal PHP Parser.

  3. Script Execution: The PHP Parser executes the embedded script logic and generates a plain HTML payload.

  4. Response Delivery: The PHP Parser returns the HTML to the web server, which sends the rendered HTML back to the client browser.

PHP blocks can be inserted anywhere within an HTML document structure.

Statements and Semicolons
  • PHP code consists of a sequence of statements.

  • Every individual PHP statement MUST end with a terminating semicolon ;.

Case Sensitivity Rules
  • Case-Insensitive Primitives: Core language keywords (if, else, while, echo, etc.), class names, built-in functions, and user-defined functions are case-insensitive. The statements ECHO, echo, and EcHo operate identically.

  • Case-Sensitive Variables: All variable names ARE strictly case-sensitive. Declaring $color does not define $COLOR or $coLOR.

Comments in PHP

Comments are non-executing text lines used for developer documentation, code clarification, or temporarily disabling script segments.

Core Variable Principles

Variables serve as containers for storing data types such as text strings, integers, floats, and arrays.

  • No Explicit Declaration: Variables do not require explicit type declaration before assignment.

  • Implicit Data Typing: PHP automatically assigns and converts variable data types depending on the assigned value.

  • Scope & Reusability: Once defined, a variable can be reassigned and accessed throughout its executable scope.

  • Assignment Operator: Values are bound to variables using the assignment operator =.

Syntax and Declaration

Declaring a variable follows the construct $variable_name = value;.

Variable Naming Conventions
  1. A variable name MUST always begin with a dollar sign $.

  2. The character immediately following the $ MUST be a letter (a-z, A-Z) or an underscore _.

  3. A variable name CANNOT begin with a number.

  4. Variable names can ONLY contain alphanumeric characters and underscores (A-z, 0-9, and _).

  5. Spaces are strictly forbidden within variable names.

  6. Variable names are strictly case-sensitive ($x and $X are two separate variables).

Output Statements: Echo and Print

PHP provides two basic constructs to output data to the output stream: echo and print.

Functional Comparison
  • echo: Has no return value, can take multiple parameters, and is marginally faster.

  • print: Has a return value of 1 (can be used in expressions), takes only one argument, and is slightly slower than echo.

PHP Operators

Operators represent operations performed on variables and values.

  • Arithmetic Operators: Process numeric values to evaluate fundamental mathematical calculations (+, -, *, /, %, **).

  • Assignment Operators: Evaluate expressions and store the result into the left operand (=, +=, -=, *=, /=, %=).

  • Comparison Operators: Compare two scalar values (numbers or text strings) and return a boolean true or false (==, ===, !=, <>, !==, >, <, >=, <=, <=>).

  • Increment / Decrement Operators: Modify variable integer or float values by one (++$x, $x++, --$x, $x--).

  • Logical Operators: Evaluate combined conditional expressions (and, or, xor, &&, ||, !).

  • String Operators: Specially designed for handling text strings (. for concatenation, .= for concatenation assignment).

  • Array Operators: Compare and merge PHP arrays (+, ==, ===, !=, <>, !==).

  • Conditional Assignment Operators: Set variable values based on conditional checks (Ternary ?:, Null coalescing ??).

Web Forms Architecture

An HTML web form provides a document containing user input controls (GUI elements such as text fields, radio buttons, checkboxes, dropdowns, and submit buttons) that allow users to enter or select data. Forms transmit collected user inputs to a web server for processing, session handling, or database storage.

The HTTP Protocol

Communication between client web browsers and web servers occurs via the Hypertext Transfer Protocol (HTTP), a request-response protocol:

  1. HTTP Request: The client browser submits a request message to the web server.

  2. HTTP Response: The web server processes the request and responds with status metadata and payload content.

HTTP GET Method

The GET method requests data from a specified resource by appending payload parameter key/value pairs directly into the URL query string.

Characteristics of GET Requests
  • Parameters are appended directly to the URL string (e.g., getmethod.php?username=John&city=NewYork).

  • GET requests can be cached by browsers.

  • GET requests remain stored in browser history.

  • GET requests can be saved as browser bookmarks.

  • GET requests have strict data length limits due to URL length restrictions.

  • GET requests only permit ASCII character encodings.

  • GET requests are intended exclusively for requesting data (read-only operations), not modifying server state.

  • Security Risk: GET requests expose data in the browser address bar and must NEVER be used when transmitting sensitive information such as passwords or tokens.

HTTP POST Method

The POST method transmits user payload data encapsulated within the message body of the HTTP request.

Characteristics of POST Requests
  • Data payload is stored within the request body rather than appended to the URL.

  • POST requests are never cached by browsers.

  • POST requests do not remain in browser history.

  • POST requests cannot be bookmarked.

  • POST requests have no payload length restrictions.

  • POST requests allow all data types, including binary data and multipart file uploads.

  • POST requests are used to create or modify data on the server.

  • Enhanced Security: Data parameters are not exposed in the URL address bar.

Exhaustive Comparison: HTTP GET vs. HTTP POST
  • Data Location: GET appends data to the URL, POST encapsulates data in the HTTP request body.

  • Data Size: GET has strict character limits, POST has unlimited payload size.

  • Security: GET is less secure (exposes parameters in address bar), POST is more secure (hidden in body).

  • Caching & History: GET requests are cached, stored in history, and bookmarkable; POST requests are never cached, not stored in history, and cannot be bookmarked.

  • Data Types: GET permits ASCII characters only, POST permits all data types including binary files.

Server Processing Workflow

Form submission, state evaluation, and session handling follow a structured workflow:

  1. Form Input: The user inputs credentials (such as a password) into client GUI form fields.

  2. Form Submission: The user submits the form via the POST method.

  3. Server Evaluation: The server receives the POST body, executes backend logic, and verifies the credentials against the database.

  4. 303 Redirect Response: Upon successful verification, the server issues a 303 HTTP response, embeds session cookies into response headers, and terminates the script.

  5. Application Access: The browser receives the redirect command, reloads the client context (index.php), and grants the user secure access to the web application.