...

/

Passing Values between Requests

Passing Values between Requests

In this lesson, we'll learn how to pass values between requests to the server.

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"
...