Skip to content
PHP Logo

How can PHP be used to randomly select and load a specific HTML start page upon refreshing?

To randomly select and load a specific HTML start page upon refreshing, you can create an array of the different start pages and then use the `array_rand()` function to select a random index from the array. You can then use a PHP `header()` function to redirect the user to the selected start page.

php
<?php
// Array of start pages
$startPages = array('start_page1.html', 'start_page2.html', 'start_page3.html');

// Select a random start page
$randomIndex = array_rand($startPages);
$randomStartPage = $startPages[$randomIndex];

// Redirect to the selected start page
header("Location: $randomStartPage");
?>