Inside the Stack Logo
Loading the Stack...

Servers & Logic: The Power Behind the Code

The Server is the dedicated machine that hosts your application code and runs the essential business logic to fulfill client requests.

What is a Web Server?

A Web Server is specialized software running on a dedicated machine (a physical or virtual computer). Its primary job is to listen for HTTP requests coming from clients (browsers) and return the appropriate HTTP responses (like HTML pages, images, or JSON data).

The Role of Server-Side Languages

Server-side languages run the business logic. This is the code that performs critical actions that the client cannot do, such as: securely validating user credentials, updating customer accounts, running complex calculations, and interacting with the database.

Popular languages used for backend development include Node.js (JavaScript), PHP, and others like Ruby and Java.

Example: The Request Process

When you submit a contact form, here is the basic server workflow:

  • The Client (browser) sends a POST request to the server.
  • The Web Server receives the request and passes it to the Backend Logic (e.g., PHP script).
  • The PHP script validates the data, stores it in the database, and possibly sends an email.
  • The Backend returns a Success Response (e.g., a "Thank You" page or a JSON status code) to the client.

PHP Example

PHP (Hypertext Preprocessor) is one of the oldest and most widely used server-side languages, powering massive applications like WordPress.

PHP code is often embedded directly within HTML, and the server executes the PHP, replacing it with the resulting HTML before sending it to the client.

Simple PHP Logic

<?php
  $user = "Guest";
  // Logic to check if user is logged in
  if (isset($_SESSION['username'])) {
    $user = $_SESSION['username'];
  }
  echo "<h3>Welcome, " . $user . "</h3>";
?>

The client only sees the final HTML output (e.g., ` <h3>Welcome, John</h3>`).

The logic is running, but where does the information go? We need a place to store it.

Continue to Data & Databases →