What are the best practices for passing search parameters like Postleitzahl in PHP pagination?

When passing search parameters like Postleitzahl (postal code) in PHP pagination, it is important to properly handle the parameters to maintain the search criteria across multiple pages. One way to achieve this is by storing the search parameters in session variables and including them in the pagination links. This ensures that the search criteria are preserved as the user navigates through the paginated results.

<?php
session_start();

// Check if search parameters are set and store them in session variables
if(isset($_GET['postleitzahl'])) {
    $_SESSION['postleitzahl'] = $_GET['postleitzahl'];
}

// Retrieve search parameters from session variables
$postleitzahl = isset($_SESSION['postleitzahl']) ? $_SESSION['postleitzahl'] : '';

// Include search parameters in pagination links
echo '<a href="page=1&postleitzahl='.$postleitzahl.'">1</a>';
echo '<a href="page=2&postleitzahl='.$postleitzahl.'">2</a>';
// Add more pagination links as needed
?>