Randomizing between two files

Hi

I’m quite new to php so please bear with me if this is a stupid question.

I have two files on my server which I want to access randomly. At the moment I’m just displaying one on my page using

<?php require("SYKESFILES/SYKESAMENITIES/ENGLAND/CUMBRIA/sykes_ambleside_amenities.php"); ?>

but I want to alternate between the one above and the one below randomly

<?php require("SYKESFILES/SYKESAMENITIES/ENGLAND/CUMBRIA/sykes_ambleside_amenities2.php"); ?>

the only difference between the two file paths is the number 2 after amenities.

Is there an easy way to achieve this?

There isn’t a true random, but you could use rand(1,2). That would randomly pick a 1 or 2. You could also go off the time and use a math function.

Sponsor our Newsletter | Privacy Policy | Terms of Service