Search⌘ K
AI Features

Passing Values between Requests

Explore how to pass values between PHP requests using query parameters to dynamically display content. Learn to modify script behavior by sending data in URLs, such as showing a variable number of images based on user interaction.

Showing a randomly generated number of cats

After /random.php generates a random number X for us, we’d like to go to a different page where we can see X cute kittens. So given we are on /random.php, and it shows the number 7, we’d like to see a link that says: “Now show me 7 kittens”. The URL for that link (the one provided in the href attribute) should somehow contain that number.

Static solution

A static solution would be to create 10 different files that look like this:

<!-- public/kittens-1.html -->
<img src="cat.jpg" alt="Cat 1">

<!-- public/kittens-2.html -->
<img src="cat.jpg" alt="Cat 1">
<img src="cat.jpg" alt="Cat 2">

<!-- public/kittens-3.html -->
<img src="cat.jpg" alt="Cat 1">
<img src="cat.jpg" alt="Cat 2">
<img src="cat.jpg" alt="Cat 3">

<!-- and so on -->

Then in random.php ...