Search Example (GET)

What's Happening

Look at the URL! After submitting, you'll see:

get-example.php?q=your%2Bsearch&category=all

This is the query string - data passed via GET is visible in the URL.

The $_GET Superglobal

PHP automatically parses the query string into $_GET:

<?php
// URL: ?q=hello&category=books

$query = $_GET['q'];        // 'hello'
$category = $_GET['category'];  // 'books'

// Always provide defaults for missing parameters
$query = $_GET['q'] ?? '';  // Empty string if 'q' not in URL
?>

Current $_GET Contents

Array
(
)

Why GET for Searches?


Back to Module | Next: POST Example