📲 Download Utility Tools Apps

EMI Calculator

Download EMI Calculator

SOA Games

Download SOA Games

SOA Technology App

Download SOA Technology

BMI Checker

Download BMI Checker

Task Jira

Download Task Jira

Laughing Adda

Download Laughing Adda

📅 हिंदी कैलेंडर ऐप डाउनलोड करें

Download Shubhcalendar App

🛠️ 19. Advanced Topics (PHP)

1️⃣ RESTful API Development

🔹 What is REST API?

REST (Representational State Transfer) is a way to build APIs using HTTP methods.

🔹 HTTP Methods:

  • GET → Fetch data
  • POST → Create data
  • PUT/PATCH → Update data
  • DELETE → Remove data

🔹 Example (Simple PHP API)

<?php
header("Content-Type: application/json");$data = [
["id" => 1, "name" => "Aditya"],
["id" => 2, "name" => "Rahul"]
];echo json_encode($data);

🔹 API Routing (Basic)

$request = $_SERVER['REQUEST_METHOD'];if ($request == 'GET') {
echo "Fetching data";
} elseif ($request == 'POST') {
echo "Creating data";
}

🔹 Best Practices:

  • Use JSON format
  • Proper HTTP status codes (200, 404, 500)
  • Secure endpoints
  • Version your API (/api/v1/)

2️⃣ Authentication (JWT & Sessions)

🔹 Session Authentication

  • Stores user data on server
  • Uses cookies
session_start();$_SESSION['user'] = "Aditya";if(isset($_SESSION['user'])){
echo "Logged in as " . $_SESSION['user'];
}

🔹 JWT (JSON Web Token)

Stateless authentication (no session stored on server)

🔹 JWT Flow:

  1. User logs in
  2. Server generates token
  3. Client stores token
  4. Token sent in headers for every request

🔹 Example (Concept)

$token = base64_encode(json_encode(["user_id" => 1]));
echo $token;

🔹 Real JWT uses:

  • Signature
  • Secret key
  • Expiry time

Libraries:

  • firebase/php-jwt

3️⃣ Middleware

🔹 What is Middleware?

Middleware acts as a filter before request reaches main logic.

🔹 Use Cases:

  • Authentication check
  • Logging
  • Rate limiting

🔹 Example

function authMiddleware() {
if(!isset($_SESSION['user'])) {
die("Unauthorized");
}
}

Usage:

authMiddleware();
echo "Protected Content";

4️⃣ Dependency Injection (DI)

🔹 What is DI?

Instead of creating objects inside a class, you pass them from outside.

❌ Without DI

class User {
public function __construct() {
$this->db = new Database();
}
}

✅ With DI

class User {
private $db; public function __construct($db) {
$this->db = $db;
}
}$db = new Database();
$user = new User($db);

🔹 Benefits:

  • Easy testing
  • Loose coupling
  • Better code structure

🚀 Pro Tips (Important for Students & Developers)

  • Use MVC framework (Laravel) for real projects
  • Always validate & sanitize input
  • Secure APIs with JWT + HTTPS
  • Use Postman for API testing
  • Follow PSR standards


AI Spiritual Tools & Interactive Experiences

Explore powerful AI-driven tools for daily guidance, spirituality, fun quizzes, and self-discovery.

Today’s Quote

Get inspiring daily quotes powered by AI to motivate and guide your day.

Explore Now

AI Tarot Card Reader

Reveal insights about your future, love, and career with AI tarot readings.

Read Tarot

Love Match Calculator

Check compatibility and love predictions using AI-based analysis.

Check Match

Fortune Cookie

Open an AI fortune cookie and receive wisdom, luck, and fun messages.

Open Cookie

Quiz Categories

Engage with knowledge-based and fun quizzes across multiple categories.

Start Quiz

Panchang Calendar

View daily Panchang, auspicious timings, tithi, nakshatra, and festivals.

View Panchang

Online Numerology

Discover your destiny number, life path, and numerology predictions.

Calculate Now

Spiritual Feeds

Stay connected with spiritual thoughts, mantras, and divine content.

View Feeds

Quiz Hub

Attempt trending quizzes on GK, spirituality, festivals, and more.

Explore Quizzes