Spex3
    

PHP Server-Side Scripting Basics 🖥️🚀


    

    

What is Server-Side Scripting?
🔹 Server-side scripting means the code runs on the web server, not in the user's browser.
🔹 The server processes the PHP code and sends plain HTML to the user's browser.
🔹 Unlike JavaScript, which runs on the client-side, PHP handles database interactions, authentication, file handling, and more.

How PHP Works on the Server?
1️⃣ A user requests a .php page (e.g., index.php).
2️⃣ The web server (Apache, Nginx) processes the PHP script.
3️⃣ PHP executes the code, interacts with a database (if needed).
4️⃣ The server sends back the processed HTML to the browser.

✅ Example: Server processes PHP and sends HTML


echo "Hello, World!"; // PHP code executes on the server
?>

🔹 Output in browser:


Hello, World!

Writing Your First PHP Script

🔹 PHP code is written inside tags.
🔹 The default file extension for PHP files is .php.
🔹 Save your script in a web server directory (e.g., htdocs for XAMPP).

Example: Basic PHP Script


// This is a PHP comment
echo "

Welcome to PHP!

";
?>

✅ Steps to Run:

Save the file as index.php in your server root folder.

Start your local server (XAMPP, WAMP, etc.).

Open http://localhost/index.php in your browser.

Embedding PHP in HTML

🔹 You can mix PHP with HTML for dynamic web pages.

Example: Mixing PHP and HTML




✅ Output:



Welcome, John Doe!

Server-Side vs Client-Side Scripting

Feature Server-Side (PHP) Client-Side (JavaScript)

Execution On web server In the browser

Security More secure Less secure

Interacts with Database? ✅ Yes ❌ No

Generates HTML? ✅ Yes ❌ No

Example Uses Authentication, file handling, APIs Form validation, UI effects


    Date: 2025-03-24 00:00:00.000000