A button that randomly chooses urls from the list

Good morning I am Anna. I am an artist and have a website with my drawings and would like to make a button that can randomly open a new page after it is pressed.

As an example: www.boredbutton.com

I tried to see the website source to find out the code that randomly chooses the pages but all I could find is the form html:

<form name="bored" method="post" action="/random" class="button">    
	<input type="image" name="submit" src="/i/boredButton.png" value="Bored No More" />
	<input type="hidden" value="submit" name="ie7sucks">
</form>	

If you know what is the rest script code I need to add to my root directory where I can add the random pages I would be very thankful for your help.

I think you need php or JavaScript; try searching google for something like javascript select random page or php select random page.

Where do you have those url stored? txt file, database?

Then the chances are it’s done with server-side scripting.

I made a recent post here about randomising content via php.
The same method could be used for URLs instead of images.

almost certainly in whatever the action=“/random” calls.

I am a noobie at this. I can put any file in the root directory of my website for example if I will create a file called random.php what code should I put there so the button that is placed on my html pages randomly selects urls from that random.php
I just need a simple code, nothing complicated so I can just add or remove pages from random.php file whenever I need. Thank you for your time.

Maybe something like this?

<?php
$urlList    = array("URL1", "URL2", "URL3", "URL4", "URL5");
$randUrl    = rand(0, (count($urlList ) - 1));
?>
    
<a href="<?=$urlList[$randUrl]; ?>"><?=$urlList[$randUrl]; ?></a>

Just expanding on the post by @donboe
“URL1” would be replaced with “/i/boredButton.png” but in your case @AnnaRosendale it could be a webpage and not an image depending how you have things setup.

If you have a lot of pages it might be easier to have them in one directory so that you can build the array of pages automatically This means you do not need to edit the php every time you add a new page.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.