WebDev 2 Lesson 3 PHP WAMP XAMPP
WebDev 2 Lesson 3 PHP WAMP XAMPP
Local Server
Environments
•Overview
Local server environments like
XAMPP and WAMP provide the
necessary components for
developing and testing web
applications on your local machine
These tools simulate a web server
environment similar to live servers,
enabling developers to test their
PHP code without needing to deploy
it online
Overview of XAMPP
• Components of XAMPP
Apache: A widely-used web server
software
MariaDB/MySQL: Databases used to
store and manage data
PHP: The server-side scripting
language
Perl: A programming language for
scripting
Detailed Overview
of XAMPP
• Installation Process
Download: Obtain the XAMPP installer from the
official Apache Friends website
Run Installer: Follow the setup wizard; select
components to install
Configure Ports: By default, XAMPP uses port 80 for
Apache and 3306 for MySQL
Starting Services: Use the XAMPP Control Panel to
start and stop Apache and MySQL services
Verification: Access http://localhost in a web
browser to ensure that the server is running
Introduction to
WAMP
• Components of WAMP
Apache: Web server software
MySQL: Database management system
PHP: Server-side scripting language
• Installation Process
Download: Get the WAMP installer from the WAMPServer
website
Run Installer: Follow the setup instructions and select the desired
PHP version
Configure: The WAMP icon in the system tray allows you to
start/stop services and switch PHP versions
Verification: Visit http://localhost to check if WAMP is correctly
installed
Troubleshooting
Common Issues
• Port Conflicts
XAMPP: Change the default port from 80 to another port if port 80 is used
by another application
WAMP: Adjust the port settings in the httpd.conf file if Apache does not
start
• Firewall and Security Settings
Ensure that firewall settings allow Apache and MySQL to communicate
• Service Not Starting
Check error logs in the XAMPP or WAMP control panel to identify issues
• Hands-On Installation
Have students download and install XAMPP or WAMP on their machines
Assist with configuration and initial setup
Introduction to PHP
•Overview
PHP is a server-side scripting
language designed for web
development
PHP scripts are executed on the
server, and the output is sent to the
client as HTML
Basic Syntax of
PHP
• PHP Tags
PHP code is enclosed in <?php ?> tags.
Everything within these tags is processed
as PHP code.
Example
Basic Syntax of
PHP
• Statements and Semicolons
• Each PHP statement ends with a semicolon (;)
• Example
Variables and Data
Types
• Declaring Variables
Variables start with a dollar sign , followed
by the variable name
Example
Variables and Data
Types
• Data Types
String: Represents text
Integer: Represents whole numbers
Float: Represents decimal numbers
Boolean: Represents true or false values
Array: Stores multiple values
Example
Variables and Data
Types
• Data Types
Case Sensitivity and
Naming Conventions
•Case Sensitivity
▪ PHP variables are case-
sensitive
•Naming Conventions
▪ Use meaningful names
for variables
▪ Follow conventions like
camelCase or
snake_case for
readability
Introduction to
Embedding PHP
•Overview
PHP can be embedded within HTML
to create dynamic web pages where
the content is generated on the
server side
Basic Embedding
Example
Explanation
• The <?php echo "Welcome to My Website"; ?> line
within the <h1> tag is PHP code. The echo
statement outputs the string "Welcome to My
Website" as HTML content. When the PHP code is
processed on the server, it replaces the PHP tags
with the output, resulting in <h1>Welcome to My
Website</h1>.
• Similarly, <?php echo date('Y-m-d'); ?> within the
<p> tag outputs the current date in Y-m-d format.
This shows how PHP can generate dynamic content
like the current date.
Dynamic Content
Generation
• Explanation:
• The PHP code <?php $username = "Alice"; ?>
initializes a variable $username with the
value "Alice".
• Within the HTML <h2> tag, <?php echo
$username; ?> outputs the value of the
$username variable. This dynamically inserts
"Alice" into the HTML content, resulting in
<h2>Welcome, Alice!</h2>.
• This demonstrates how PHP variables can be
used to personalize content.
Processing HTML
Forms with PHP
• Form Handling
PHP can process data submitted via HTML
forms
Explanation
• The HTML form collects user input
• When the form is submitted, PHP
processes the form data
• htmlspecialchars is used to prevent XSS
attacks by converting special characters to
HTML entities
• The PHP code outputs the sanitized user
input within a greeting message, e.g.,
"Hello, John" if the user enters "John" in
the form
Introduction to
Embedding HTML in PHP
• Overview
Embedding HTML in PHP is useful for generating
dynamic HTML content based on PHP logic
• Example of Echoing HTML
Use echo or print to output HTML tags
Explanation
• The echo statement in PHP outputs HTML directly
• Similarly, echo "<p>This is a paragraph.</p>";
outputs a <p> paragraph
• This demonstrates how PHP can be used to output
entire blocks of HTML code
Generating Dynamic
HTML with Loops
• Example of Dynamic Lists
• PHP loops, such as foreach, can be used to
generate repetitive HTML structures dynamically
• $fruits is an array containing fruit names
• The result is an HTML unordered list with each fruit
name in a list item
Explanation
• PHP loops, such as foreach, can be used to
generate repetitive HTML structures dynamically.
• $fruits is an array containing fruit names. The
foreach loop iterates over each element,
outputting an <li> element for each fruit.
• The result is an HTML unordered list (<ul>) with
each fruit name in a list item (<li>). This is useful
for generating lists, tables, or other repetitive
HTML content based on data.
Conditional HTML
Output
• Example of Conditional Output
Use if statements to display different HTML content
based on conditions
Explanation
• The if statement checks the condition of
$isLoggedIn
• This demonstrates how PHP can control the
content displayed on the web page based on
conditions, such as user authentication status
Interactive Segment:
Creating Dynamic HTML
• Hands-On Practice
Have students write a PHP script that outputs
different HTML content based on certain
conditions