Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

PHP Programming — Free Notes & Tutorial

Learn PHP for server-side web development — syntax, functions, forms, sessions and MySQL. Free PHP course at SikshaSarovar.

This PHP Programming course is part of Siksha Sarovar and is 100% free for students in India — no sign-up required to read. It contains 29 structured lessons with examples, and pairs with our free online compiler and AI tutor.

What you will learn

  • PHP syntax
  • Functions
  • MySQL
  • Sessions
  • Forms

Course content (29 lessons)

  1. 1. Introduction to PHP — What is PHP? PHP (Hypertext Preprocessor) is a server-side scripting language mainly used to create dynamic and interactive web pages . PHP scripts are executed on the server ,…
  2. 2. PHP Syntax & Comments — Default Syntax of PHP PHP code is written inside PHP tags and executed on the server . Basic PHP Syntax Important Rules PHP statements end with a semicolon (;) PHP is…
  3. 3. Data Types & Output — Output Functions in PHP Output functions are used to display data on the browser. 1. echo Most commonly used Faster than print Can display multiple values 2. print Similar to echo…
  4. 4. Configuration & Errors — Configuration Settings (php.ini) PHP behavior is controlled using the php.ini configuration file. Common Configuration Settings Setting Description :--- :--- display errors Shows…
  5. 8. Control Structures - Execution Control — Execution Control Statements Execution control statements are used to change the normal flow of program execution. 1. break Statement Terminates the loop or switch statement…
  6. 9. Control Structures - Conditionals — Conditional Statements Conditional statements are used to execute code based on conditions . 1. if Statement Executes code when condition is true. 2. if–else Statement Executes…
  7. 10. Control Structures - Loops — Looping Statements (with Real-Time Examples) Loops are used to repeat a block of code . 1. for Loop Used when number of iterations is known. [!NOTE] Real-time Example: Displaying…
  8. 11. Functions in PHP — Functions in PHP A function is a block of code that performs a specific task and can be reused. Creating Functions Syntax Example [!NOTE] Exam Line: Functions increase code…
  9. 12. Arrays & Types — Arrays in PHP An array is a special variable that can store multiple values in a single variable , instead of creating separate variables for each value. Why Arrays are Needed?…
  10. 13. Array Operations & Functions — Traversing Arrays Traversing means accessing each element of an array one by one . 1. Traversing Using for Loop (Indexed Array) [!NOTE] Used When: Index values are known. 2.…
  11. 14. Include Functions — Include Functions in PHP Include functions are used to insert the content of one PHP file into another PHP file . They help in code reusability , easy maintenance , and modular…
  12. 15. Regular Expressions — Regular Expressions in PHP A Regular Expression (RegEx) is a pattern used to search, match, or validate text . Why Regular Expressions are Used? Validate form inputs Check email…
  13. 16. OOP Fundamentals — Object-Oriented Programming (OOP) in PHP Object-Oriented Programming (OOP) is a programming approach that organizes code using classes and objects , making programs modular,…
  14. 17. Encapsulation & Inheritance — Encapsulation Encapsulation means binding data and methods together and restricting direct access . Access Modifiers Modifier Scope :--- :--- public Anywhere private Same class…
  15. 18. OOP Essential Features — Constructor and Destructor Constructor Called automatically when an object is created. Destructor Called automatically when an object is destroyed. [!NOTE] Exam Line: Constructors…
  16. 19. Advanced OOP — Magic Method: set() The set() method is called automatically when assigning a value to an inaccessible property . [!TIP] Exam Tip: set() is used for controlled property…
  17. 20. MySQL Integration & Functions — PHP with MySQL PHP and MySQL are widely used together to create dynamic, database-driven web applications such as login systems, registration forms, e-commerce websites, etc. What…
  18. 21. Database Operations & Security — Grid / Data Grid Options (Tabular Display) Data grid means displaying database records in table format . Common Grid Features View records Edit / Delete buttons Sorting Paging…
  19. 22. Advanced Database Features — Uploading Images into Database Steps 1. HTML file upload form 2. Store image in folder 3. Save image path in database HTML Form PHP Code --- Downloading / Displaying Images from…
  20. 23. Strings & String Functions — String Variables in PHP A string is a sequence of characters enclosed within quotes. [!NOTE] Exam Definition: A string is a collection of characters stored inside single or double…
  21. 24. Regular Expressions (POSIX) — Regular Expressions (POSIX) A Regular Expression (RegEx) is a pattern used to search or match strings . [!NOTE] Exam Definition: Regular expressions are patterns used for string…
  22. 25. File System & Disk Operations — Working with Files and Operating System in PHP PHP provides built-in functions to interact with the file system, directories, and disk resources . These features are widely used…
  23. 26. Error & Exception Handling — Error and Exception Handling in PHP Error and exception handling helps in detecting, managing, and debugging runtime problems safely. Error Logging Error logging stores error…
  24. 27. Date & Time Functions — Date and Time Functions in PHP Date and time functions are used to display, calculate, format, and manipulate date and time values in PHP applications such as login systems,…
  25. 28. Authentication in PHP — Authentication in PHP Authentication is the process of verifying the identity of a user before allowing access to protected resources. [!NOTE] Exam Definition: Authentication…
  26. 29. Cookies in PHP — Cookies in PHP What is a Cookie? A cookie is a small piece of data stored on the user’s browser by a website. It is used to remember user information between multiple requests.…
  27. 30. Sessions in PHP — Sessions in PHP What is a Session? A session is a server-side storage mechanism used to store user data across multiple pages. [!NOTE] Exam Definition: A session stores user data…
  28. 31. Web Services (SOAP, RSS & REST) — Web Services What is a Web Service? A Web Service is a software system that allows different applications to communicate with each other over the internet , regardless of the…
  29. 32. XML Integration in PHP — XML Integration in PHP What is XML? XML (eXtensible Markup Language) is a markup language used to store and transport data in a structured and readable format . [!NOTE] Exam…

1. Introduction to PHP

What is PHP?

PHP (Hypertext Preprocessor) is a server-side scripting language mainly used to create dynamic and interactive web pages. PHP scripts are executed on the server, and the result is sent to the browser as HTML.

Key Features of PHP

  • Open-source and free
  • Easy to learn for beginners
  • Works well with HTML
  • Supports databases like MySQL, PostgreSQL, Oracle
  • Platform independent (Windows, Linux, macOS)

---

History of PHP

  • 1994: PHP was created by Rasmus Lerdorf
  • Initially called Personal Home Page Tools
  • Used to track visits to his online resume
  • Later rewritten and expanded to support databases
  • PHP became very popular for web development

Important Timeline

YearEvent
1994PHP created
1995PHP Tools released publicly
1997PHP/FI introduced
1998PHP 3 released
2000PHP 4 released
2004PHP 5 released
2015PHP 7 released
2020PHP 8 released
Exam Tip: PHP was created by Rasmus Lerdorf in 1994.

---

Versions of PHP and Differences

PHP 3

  • First official version
  • Introduced server-side scripting
  • Limited features

PHP 4

  • Improved performance
  • Introduced Zend Engine
  • Better handling of variables

PHP 5

  • Introduced Object-Oriented Programming (OOP)
  • Better database support
  • XML and exception handling added

PHP 7

  • Major performance improvement
  • Faster execution
  • Reduced memory usage
  • Removed old and unused features

PHP 8

  • Just-In-Time (JIT) compiler
  • Improved error handling
  • New syntax features
  • Better security

Difference Summary Table

FeaturePHP 5PHP 7PHP 8
SpeedModerateFastVery Fast
OOP SupportYesYesAdvanced
Memory UsageHighLowLower
Error HandlingBasicImprovedStrong
Exam Tip: PHP 7 and PHP 8 are faster and more secure than older versions.

---

Practicality of PHP

PHP is very practical for real-world web applications.

Why PHP is Practical?

  • Easy integration with HTML
  • Large community support
  • Runs on most servers
  • Supports many databases
  • Used in real websites like:
  • Facebook (initially)
  • Wikipedia
  • WordPress

Common Uses

  • Login systems
  • Registration forms
  • E-commerce websites
  • Content Management Systems (CMS)
  • Dynamic web pages
Exam Point: PHP is practical because it is easy to use, flexible, and widely supported.

---

Power of PHP

PHP is considered powerful because it can handle both simple and complex web applications.

What Makes PHP Powerful?

  • Handles form data easily
  • Session and cookie management
  • File handling on server
  • Database connectivity
  • Supports OOP concepts
  • Secure with encryption and hashing

PHP Can

  • Generate dynamic page content
  • Create, read, update, delete files
  • Collect form data
  • Send and receive cookies
  • Control user access
Exam Line: PHP is powerful due to its database support, server control, and scalability.

---

Installation and Configuring Apache and PHP

To run PHP, we need:

  1. Web Server (Apache)
  2. PHP Interpreter
  3. Browser

Option 1: Using XAMPP (Recommended for Beginners)

XAMPP includes:

  • Apache Server
  • PHP
  • MySQL
  • phpMyAdmin

Steps to Install XAMPP

  1. Download XAMPP from official website
  2. Install XAMPP
  3. Open XAMPP Control Panel
  4. Start Apache
  5. Check by opening: http://localhost

Testing PHP

Create a file named test.php inside htdocs folder:

<?php
echo "Hello PHP";
?>

Open in browser: http://localhost/test.php

Option 2: Manual Installation (Theory Point)

Steps

  1. Install Apache Server
  2. Install PHP
  3. Configure php.ini
  4. Link PHP with Apache
  5. Restart Apache server
Exam Tip: XAMPP is commonly used for PHP development because it is easy to install and configure.

---

Advantages of PHP

  • Free and open source
  • Easy learning curve
  • Fast execution
  • Cross-platform
  • Large documentation

Limitations of PHP

  • Not suitable for desktop applications
  • Security depends on proper coding
  • Slower than compiled languages

2. PHP Syntax & Comments

Default Syntax of PHP

PHP code is written inside PHP tags and executed on the server.

Basic PHP Syntax

<?php
   // PHP code goes here
?>

Important Rules

  • PHP statements end with a semicolon (;)
  • PHP is case-sensitive for variables
  • Keywords like echo, if, while are not case-sensitive

Example

<?php
echo "Welcome to PHP";
?>
Exam Point: PHP code must be written inside <?php ?> tags.

---

Styles of PHP Tags

PHP supports different tag styles to write PHP code.

1. Standard PHP Tags (Recommended)

<?php
echo "Hello PHP";
?>
  • Verified: Most commonly used
  • Verified: Supported on all servers

2. Short Open Tags

<?
echo "Hello PHP";
?>
  • Warning: Not recommended
  • Warning: May be disabled on some servers

3. Short Echo Tags

<?= "Hello PHP"; ?>
  • Use: Used for quick output
  • Support: Mostly supported in modern PHP versions

4. ASP Style Tags

<%
echo "Hello PHP";
%>
  • Status: Deprecated
  • Status: Not used in modern PHP

Comparison Table

Tag TypeUsageRecommendation
Standard<?php ?>✅ Best
Short Open<? ?>❌ Avoid
Short Echo<?= ?>⚠ Limited
ASP Style<% %>❌ Not used
Exam Tip: Standard PHP tags are the safest and most recommended.

---

Comments in PHP

Comments are used to explain code and are ignored by the PHP interpreter.

1. Single-Line Comment

// This is a single-line comment
# This is also a single-line comment

2. Multi-Line Comment

/*
This is a
multi-line comment
*/

Why Use Comments?

  • Improves code readability
  • Helps in debugging
  • Useful for documentation
Exam Line: Comments are non-executable lines used to explain PHP code.

Frequently asked questions

Is the PHP Programming course really free?

Yes. The entire PHP Programming course on Siksha Sarovar is free to read with no account required. You can optionally sign in with Google to save your progress.

Do I get a certificate for PHP Programming?

Yes — finish the lessons and pass the quiz to earn a free, verifiable certificate you can share on LinkedIn or with recruiters.

Can I run code while learning?

Yes. The built-in online compiler runs C, C++, Python, Java, PHP, JavaScript, C# and SQL directly in your browser — no installation needed.