Uncategorized

Introduction to Web Development with PHP – Module 1 for Beginners

📘 Module 1: Introduction to Web & PHP

✅ 1. What is a Website & How It Works

  • A website is a collection of related web pages hosted on a server.
  • Users access websites using browsers by typing a URL like https://www.example.com.
  • The browser sends an HTTP request to the server, which responds with HTML/CSS/JS files.

Basic flow of how a website works:


1. User enters a URL in browser → www.example.com
2. DNS translates domain to IP → 192.168.1.1
3. Request sent to web server (Apache/Nginx)
4. Server processes request and sends back response (HTML/CSS/JS)
5. Browser renders the content on screen
  

✅ 2. Client vs Server-side Technologies

  • Client-side: Code that runs in the browser (HTML, CSS, JavaScript).
  • Server-side: Code that runs on the server (PHP, Python, Node.js, etc).

Client vs Server Example:


Client: Sends form data (like login info) using HTML/JS
Server: PHP receives form data, checks database, returns result
  

✅ 3. Installing XAMPP / WAMP / MAMP

  • Install XAMPP (Windows/Linux) or MAMP (Mac).
  • XAMPP includes Apache, MySQL, PHP, and phpMyAdmin.
  • Start Apache and MySQL from the XAMPP Control Panel.
  • Your localhost URL: http://localhost/

Directory for PHP files: C:/xampp/htdocs/

✅ 4. Creating First PHP File (hello.php)

Inside your htdocs folder, create a new file called hello.php with this code:


<?php
  echo "Hello, world!";
?>
  

Then open your browser and go to:

http://localhost/hello.php

✅ 5. PHP Syntax and Tags

  • PHP code is written inside <?php ... ?> tags.
  • Each statement ends with a semicolon ;.
  • PHP is case-insensitive for functions (e.g., echo = ECHO).

<?php
  $name = "Umar";
  echo "Welcome, " . $name;
?>
  

✅ 6. Echo and Print

  • echo and print are both used to output text.
  • echo is slightly faster and can output multiple values.

<?php
  echo "Hello ";
  echo "World!<br>";
  print "This is printed using print!";
?>
  

✅ 7. PHP Comments

  • Single-line comments: // or #
  • Multi-line comments: /* ... */

<?php
  // This is a single-line comment
  # This is also a single-line comment

  /* This is a
     multi-line comment */
  echo "Comments are ignored by PHP!";
?>
  

Leave a Reply

Your email address will not be published. Required fields are marked *