What are the potential ways to change an image server-side based on user input in PHP?

To change an image server-side based on user input in PHP, you can use a form to collect the user input and then process it using PHP to determine which image to display. You can store the image file paths in an array or database and retrieve the appropriate image based on the user input.

<?php
// Define an array of image file paths
$images = [
    'image1.jpg',
    'image2.jpg',
    'image3.jpg'
];

// Get user input from a form
$userInput = $_POST['user_input'];

// Determine which image to display based on user input
if ($userInput == 'option1') {
    $selectedImage = $images[0];
} elseif ($userInput == 'option2') {
    $selectedImage = $images[1];
} elseif ($userInput == 'option3') {
    $selectedImage = $images[2];
} else {
    $selectedImage = 'default.jpg';
}

// Display the selected image
echo '<img src="' . $selectedImage . '" alt="Selected Image">';
?>